bug_test.go

 1package tests
 2
 3import (
 4	"github.com/MichaelMure/git-bug/bug"
 5	"github.com/MichaelMure/git-bug/repository"
 6
 7	"testing"
 8)
 9
10func TestBugId(t *testing.T) {
11	mockRepo := repository.NewMockRepoForTest()
12
13	bug1 := bug.NewBug()
14
15	bug1.Append(createOp)
16
17	err := bug1.Commit(mockRepo)
18
19	if err != nil {
20		t.Fatal(err)
21	}
22
23	bug1.Id()
24}
25
26func TestBugValidity(t *testing.T) {
27	mockRepo := repository.NewMockRepoForTest()
28
29	bug1 := bug.NewBug()
30
31	if bug1.Validate() == nil {
32		t.Fatal("Empty bug should be invalid")
33	}
34
35	bug1.Append(createOp)
36
37	if bug1.Validate() != nil {
38		t.Fatal("Bug with just a CreateOp should be valid")
39	}
40
41	err := bug1.Commit(mockRepo)
42	if err != nil {
43		t.Fatal(err)
44	}
45
46	bug1.Append(createOp)
47
48	if bug1.Validate() == nil {
49		t.Fatal("Bug with multiple CreateOp should be invalid")
50	}
51
52	err = bug1.Commit(mockRepo)
53	if err == nil {
54		t.Fatal("Invalid bug should not commit")
55	}
56}
57
58//func TestBugSerialisation(t *testing.T) {
59//	bug1, err := bug.NewBug()
60//	if err != nil {
61//		t.Error(err)
62//	}
63//
64//	bug1.Append(createOp)
65//	bug1.Append(setTitleOp)
66//	bug1.Append(setTitleOp)
67//	bug1.Append(addCommentOp)
68//
69//	repo := repository.NewMockRepoForTest()
70//
71//	bug1.Commit(repo)
72//
73//	bug2, err := bug.ReadBug(repo, bug.BugsRefPattern+bug1.Id())
74//	if err != nil {
75//		t.Error(err)
76//	}
77//
78//	if !reflect.DeepEqual(bug1, bug2) {
79//		t.Fatalf("%v different than %v", bug1, bug2)
80//	}
81//}