bug_test.go

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