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