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