bug_test.go

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