operation_iterator_test.go

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