operation_test.go

 1package operations
 2
 3import (
 4	"github.com/MichaelMure/git-bug/bug"
 5	"testing"
 6)
 7
 8// Different type with the same fields
 9type CreateOperation2 struct {
10	Title   string
11	Message string
12}
13
14func (op CreateOperation2) OpType() OperationType {
15	return UNKNOW
16}
17
18func (op CreateOperation2) Apply(snapshot bug.Snapshot) bug.Snapshot {
19	// no-op
20	return snapshot
21}
22
23func TestOperationsEquality(t *testing.T) {
24	var rene = bug.Person{
25		Name:  "René Descartes",
26		Email: "rene@descartes.fr",
27	}
28
29	var A Operation = NewCreateOp(rene, "title", "message")
30	var B Operation = NewCreateOp(rene, "title", "message")
31	var C Operation = NewCreateOp(rene, "title", "different message")
32
33	if A != B {
34		t.Fatal("Equal value operations should be tested equals")
35	}
36
37	if A == C {
38		t.Fatal("Different value operations should be tested different")
39	}
40
41	D := CreateOperation2{Title: "title", Message: "message"}
42
43	if A == D {
44		t.Fatal("Operations equality should handle the type")
45	}
46
47	var isaac = bug.Person{
48		Name:  "Isaac Newton",
49		Email: "isaac@newton.uk",
50	}
51
52	var E Operation = NewCreateOp(isaac, "title", "message")
53
54	if A == E {
55		t.Fatal("Operation equality should handle the author")
56	}
57}