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