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
12func ExampleOperationIterator() {
13 b := NewBug()
14
15 // add operations
16
17 it := NewOperationIterator(b)
18
19 for it.Next() {
20 // do something with each operations
21 _ = it.Value()
22 }
23}
24
25func TestOpIterator(t *testing.T) {
26 mockRepo := repository.NewMockRepoForTest()
27
28 rene := identity.NewIdentity("René Descartes", "rene@descartes.fr")
29 unix := time.Now().Unix()
30
31 createOp := NewCreateOp(rene, unix, "title", "message", nil)
32 setTitleOp := NewSetTitleOp(rene, unix, "title2", "title1")
33 addCommentOp := NewAddCommentOp(rene, unix, "message2", nil)
34 setStatusOp := NewSetStatusOp(rene, unix, ClosedStatus)
35 labelChangeOp := NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"})
36
37 bug1 := NewBug()
38
39 // first pack
40 bug1.Append(createOp)
41 bug1.Append(setTitleOp)
42 bug1.Append(addCommentOp)
43 bug1.Append(setStatusOp)
44 bug1.Append(labelChangeOp)
45 err := bug1.Commit(mockRepo)
46 assert.NoError(t, err)
47
48 // second pack
49 bug1.Append(setTitleOp)
50 bug1.Append(setTitleOp)
51 bug1.Append(setTitleOp)
52 err = bug1.Commit(mockRepo)
53 assert.NoError(t, err)
54
55 // staging
56 bug1.Append(setTitleOp)
57 bug1.Append(setTitleOp)
58 bug1.Append(setTitleOp)
59
60 it := NewOperationIterator(bug1)
61
62 counter := 0
63 for it.Next() {
64 _ = it.Value()
65 counter++
66 }
67
68 if counter != 11 {
69 t.Fatalf("Wrong count of value iterated (%d instead of 8)", counter)
70 }
71}