diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-13 16:48:55 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-13 16:48:55 +0200 |
commit | deff9e0a41eca43f832314219241c9a63cf8007e (patch) | |
tree | 215e07e7a77972cee50268603eeb3777de583e8b /bug/bug.go | |
parent | 078545538e6e6bf7a050fe6602a42a61fb5203e9 (diff) | |
download | git-bug-deff9e0a41eca43f832314219241c9a63cf8007e.tar.gz |
add basic tests for Bug and OperationIterator
Diffstat (limited to 'bug/bug.go')
-rw-r--r-- | bug/bug.go | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -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 +} |