-
Notifications
You must be signed in to change notification settings - Fork 0
/
delta_test.go
59 lines (49 loc) · 1.31 KB
/
delta_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package delta
import (
"fmt"
"testing"
)
type structDeltaSimple struct {
Field1 string
Field2 string
}
type DeltaEmbeddedStruct struct {
Test []EmbeddedStruct
}
type EmbeddedStruct struct {
DeeperTest string
}
func TestStructSimpleDeltaEqual(t *testing.T) {
s1 := structDeltaSimple{"value1", "value2"}
s2 := structDeltaSimple{"value1", "value2"}
diff, err := Struct(s1, s2)
if err != nil {
t.Errorf("Struct returned an error where one shouldn't be: %v", err)
}
if len(diff) > 0 {
t.Errorf("Should be no differences between structs, got: %v", diff)
}
}
func TestStructDeltaNotEqual(t *testing.T) {
s1 := structDeltaSimple{"value1", "value2"}
s2 := structDeltaSimple{"value1", "value3"}
diff, err := Struct(s1, s2)
if err != nil {
t.Errorf("Struct returned an error where one shouldn't be: %v", err)
}
if len(diff) != 1 {
t.Errorf("Should be no differences between structs, got: %v", diff)
}
if diff["Field2"] != "value3" {
t.Errorf("Struct reported wrong diff for struct, should be 'value3', got: '%v'", diff["Field2"])
}
}
func TestEmbeddedStruct(t *testing.T) {
s1 := DeltaEmbeddedStruct{}
s2 := DeltaEmbeddedStruct{Test: []EmbeddedStruct{EmbeddedStruct{DeeperTest: "HELLO WORLD"}}}
diff, err := Struct(s1, s2)
if err != nil {
t.Errorf("Struct returned an error: %v", err)
}
fmt.Println(diff)
}