2018-09-28 21:39:39 +03:00
|
|
|
package bug
|
2018-07-13 17:48:55 +03:00
|
|
|
|
|
|
|
import (
|
2019-08-27 13:11:51 +03:00
|
|
|
"fmt"
|
2018-07-13 17:48:55 +03:00
|
|
|
"testing"
|
2018-09-25 18:56:58 +03:00
|
|
|
"time"
|
2019-08-27 13:11:51 +03:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/identity"
|
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2018-07-13 17:48:55 +03:00
|
|
|
)
|
|
|
|
|
2019-02-01 14:22:00 +03:00
|
|
|
func ExampleOperationIterator() {
|
|
|
|
b := NewBug()
|
|
|
|
|
|
|
|
// add operations
|
|
|
|
|
|
|
|
it := NewOperationIterator(b)
|
|
|
|
|
|
|
|
for it.Next() {
|
|
|
|
// do something with each operations
|
|
|
|
_ = it.Value()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 18:07:24 +03:00
|
|
|
func TestOpIterator(t *testing.T) {
|
2018-09-15 14:15:00 +03:00
|
|
|
mockRepo := repository.NewMockRepoForTest()
|
2018-07-13 17:48:55 +03:00
|
|
|
|
2019-02-16 19:32:30 +03:00
|
|
|
rene := identity.NewIdentity("René Descartes", "rene@descartes.fr")
|
|
|
|
unix := time.Now().Unix()
|
|
|
|
|
|
|
|
createOp := NewCreateOp(rene, unix, "title", "message", nil)
|
|
|
|
addCommentOp := NewAddCommentOp(rene, unix, "message2", nil)
|
|
|
|
setStatusOp := NewSetStatusOp(rene, unix, ClosedStatus)
|
|
|
|
labelChangeOp := NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"})
|
|
|
|
|
2019-08-27 13:11:51 +03:00
|
|
|
var i int
|
|
|
|
genTitleOp := func() Operation {
|
|
|
|
i++
|
|
|
|
return NewSetTitleOp(rene, unix, fmt.Sprintf("title%d", i), "")
|
|
|
|
}
|
|
|
|
|
2018-09-28 21:39:39 +03:00
|
|
|
bug1 := NewBug()
|
2018-07-13 17:48:55 +03:00
|
|
|
|
2018-09-24 21:19:16 +03:00
|
|
|
// first pack
|
2018-07-13 17:48:55 +03:00
|
|
|
bug1.Append(createOp)
|
2018-07-18 17:41:09 +03:00
|
|
|
bug1.Append(addCommentOp)
|
2018-07-18 01:16:06 +03:00
|
|
|
bug1.Append(setStatusOp)
|
2018-07-18 17:41:09 +03:00
|
|
|
bug1.Append(labelChangeOp)
|
2019-01-19 21:23:31 +03:00
|
|
|
err := bug1.Commit(mockRepo)
|
|
|
|
assert.NoError(t, err)
|
2018-07-13 17:48:55 +03:00
|
|
|
|
2018-09-24 21:19:16 +03:00
|
|
|
// second pack
|
2019-08-27 13:11:51 +03:00
|
|
|
bug1.Append(genTitleOp())
|
|
|
|
bug1.Append(genTitleOp())
|
|
|
|
bug1.Append(genTitleOp())
|
2019-01-19 21:23:31 +03:00
|
|
|
err = bug1.Commit(mockRepo)
|
|
|
|
assert.NoError(t, err)
|
2018-07-13 17:48:55 +03:00
|
|
|
|
2018-09-24 21:19:16 +03:00
|
|
|
// staging
|
2019-08-27 13:11:51 +03:00
|
|
|
bug1.Append(genTitleOp())
|
|
|
|
bug1.Append(genTitleOp())
|
|
|
|
bug1.Append(genTitleOp())
|
2018-07-13 17:48:55 +03:00
|
|
|
|
2018-09-28 21:39:39 +03:00
|
|
|
it := NewOperationIterator(bug1)
|
2018-07-13 17:48:55 +03:00
|
|
|
|
|
|
|
counter := 0
|
|
|
|
for it.Next() {
|
|
|
|
_ = it.Value()
|
|
|
|
counter++
|
|
|
|
}
|
|
|
|
|
2019-08-27 13:11:51 +03:00
|
|
|
assert.Equal(t, 10, counter)
|
2018-07-13 17:48:55 +03:00
|
|
|
}
|