aboutsummaryrefslogtreecommitdiffstats
path: root/bug/bug.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-13 16:48:55 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-13 16:48:55 +0200
commitdeff9e0a41eca43f832314219241c9a63cf8007e (patch)
tree215e07e7a77972cee50268603eeb3777de583e8b /bug/bug.go
parent078545538e6e6bf7a050fe6602a42a61fb5203e9 (diff)
downloadgit-bug-deff9e0a41eca43f832314219241c9a63cf8007e.tar.gz
add basic tests for Bug and OperationIterator
Diffstat (limited to 'bug/bug.go')
-rw-r--r--bug/bug.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/bug/bug.go b/bug/bug.go
index 807f614f..b36246e3 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -37,7 +37,7 @@ func NewBug() (*Bug, error) {
// IsValid check if the Bug data is valid
func (bug *Bug) IsValid() bool {
// non-empty
- if len(bug.Packs) == 0 {
+ if len(bug.Packs) == 0 && bug.Staging.IsEmpty() {
return false
}
@@ -48,9 +48,16 @@ func (bug *Bug) IsValid() bool {
}
}
+ // check if Staging is valid if needed
+ if !bug.Staging.IsEmpty() {
+ if !bug.Staging.IsValid() {
+ return false
+ }
+ }
+
// The very first Op should be a CREATE
- firstOp := bug.Packs[0].Operations[0]
- if firstOp.OpType() != CREATE {
+ firstOp := bug.firstOp()
+ if firstOp == nil || firstOp.OpType() != CREATE {
return false
}
@@ -82,3 +89,17 @@ func (bug *Bug) Commit() {
func (bug *Bug) HumanId() string {
return bug.Id.String()
}
+
+func (bug *Bug) firstOp() Operation {
+ for _, pack := range bug.Packs {
+ for _, op := range pack.Operations {
+ return op
+ }
+ }
+
+ if !bug.Staging.IsEmpty() {
+ return bug.Staging.Operations[0]
+ }
+
+ return nil
+}