-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers_test.go
95 lines (89 loc) · 1.8 KB
/
matchers_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package matchers_test
import (
"testing"
v1 "github.com/afritzler/protoequal/test/api/v1"
"github.com/onsi/gomega"
"google.golang.org/protobuf/proto"
matchers "github.com/afritzler/protoequal"
)
func TestProtoEqualMatcher(t *testing.T) {
g := gomega.NewWithT(t)
// Define test cases
testCases := []struct {
name string
actual proto.Message
expected proto.Message
shouldMatch bool
}{
{
name: "Should match identical messages",
actual: &v1.Foo{
Bar: "test-bar",
Baz: "test-baz",
Qux: &v1.Qux{
Driver: "foo-driver",
Handle: "foo-handle",
},
},
expected: &v1.Foo{
Bar: "test-bar",
Baz: "test-baz",
Qux: &v1.Qux{
Driver: "foo-driver",
Handle: "foo-handle",
},
},
shouldMatch: true,
},
{
name: "Should not match different messages",
actual: &v1.Foo{
Bar: "test-bar",
Baz: "test-baz",
Qux: &v1.Qux{
Driver: "foo-driver",
Handle: "foo-handle",
},
},
expected: &v1.Foo{
Bar: "different-bar",
Baz: "test-baz",
Qux: &v1.Qux{
Driver: "foo-driver",
Handle: "foo-handle",
},
},
shouldMatch: false,
},
{
name: "Should not match messages with different nested fields",
actual: &v1.Foo{
Bar: "test-bar",
Baz: "test-baz",
Qux: &v1.Qux{
Driver: "foo-driver",
Handle: "foo-handle",
},
},
expected: &v1.Foo{
Bar: "test-bar",
Baz: "test-baz",
Qux: &v1.Qux{
Driver: "different-driver",
Handle: "foo-handle",
},
},
shouldMatch: false,
},
}
// Run test cases
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.shouldMatch {
g.Expect(tc.actual).To(matchers.ProtoEqual(tc.expected))
} else {
g.Expect(tc.actual).ToNot(matchers.ProtoEqual(tc.expected))
}
})
}
}