1package bug
2
3import (
4 "github.com/MichaelMure/git-bug/identity"
5 "github.com/MichaelMure/git-bug/repository"
6 "github.com/stretchr/testify/assert"
7
8 "testing"
9 "time"
10)
11
12var (
13 rene = identity.NewIdentity("René Descartes", "rene@descartes.fr")
14 unix = time.Now().Unix()
15
16 createOp = NewCreateOp(rene, unix, "title", "message", nil)
17 setTitleOp = NewSetTitleOp(rene, unix, "title2", "title1")
18 addCommentOp = NewAddCommentOp(rene, unix, "message2", nil)
19 setStatusOp = NewSetStatusOp(rene, unix, ClosedStatus)
20 labelChangeOp = NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"})
21)
22
23func TestOpIterator(t *testing.T) {
24 mockRepo := repository.NewMockRepoForTest()
25
26 bug1 := NewBug()
27
28 // first pack
29 bug1.Append(createOp)
30 bug1.Append(setTitleOp)
31 bug1.Append(addCommentOp)
32 bug1.Append(setStatusOp)
33 bug1.Append(labelChangeOp)
34 err := bug1.Commit(mockRepo)
35 assert.NoError(t, err)
36
37 // second pack
38 bug1.Append(setTitleOp)
39 bug1.Append(setTitleOp)
40 bug1.Append(setTitleOp)
41 err = bug1.Commit(mockRepo)
42 assert.NoError(t, err)
43
44 // staging
45 bug1.Append(setTitleOp)
46 bug1.Append(setTitleOp)
47 bug1.Append(setTitleOp)
48
49 it := NewOperationIterator(bug1)
50
51 counter := 0
52 for it.Next() {
53 _ = it.Value()
54 counter++
55 }
56
57 if counter != 11 {
58 t.Fatalf("Wrong count of value iterated (%d instead of 8)", counter)
59 }
60}