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