Skip to content

Commit 27795a3

Browse files
committed
add more tests
1 parent a3b0351 commit 27795a3

File tree

1 file changed

+91
-8
lines changed

1 file changed

+91
-8
lines changed

pkg/patterns/declarative/watch_test.go

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func Test_uniqueGroupVersionKind(t *testing.T) {
14-
sa := &unstructured.Unstructured{
14+
sa1 := &unstructured.Unstructured{
1515
Object: map[string]interface{}{
1616
"apiVersion": "v1",
1717
"kind": "ServiceAccount",
@@ -21,34 +21,117 @@ func Test_uniqueGroupVersionKind(t *testing.T) {
2121
},
2222
},
2323
}
24-
saObj, _ := manifest.NewObject(sa)
24+
saObj1, _ := manifest.NewObject(sa1)
25+
26+
sa2 := &unstructured.Unstructured{
27+
Object: map[string]interface{}{
28+
"apiVersion": "v1",
29+
"kind": "ServiceAccount",
30+
"metadata": map[string]interface{}{
31+
"name": "bar-operator",
32+
"namespace": "kube-system",
33+
},
34+
},
35+
}
36+
saObj2, _ := manifest.NewObject(sa2)
37+
38+
dp1 := &unstructured.Unstructured{
39+
Object: map[string]interface{}{
40+
"apiVersion": "apps/v1",
41+
"kind": "Deployment",
42+
"metadata": map[string]interface{}{
43+
"name": "frontend111",
44+
},
45+
},
46+
}
47+
dpObj1, _ := manifest.NewObject(dp1)
2548

2649
tests := []struct {
27-
name string
28-
inputObjects *manifest.Objects
29-
expectSchema []schema.GroupVersionKind
50+
name string
51+
inputObjects *manifest.Objects
52+
expectedSchema []schema.GroupVersionKind
3053
}{
3154
{
3255
name: "single object",
3356
inputObjects: &manifest.Objects{
3457
Items: []*manifest.Object{
35-
saObj,
58+
saObj1,
59+
},
60+
},
61+
expectedSchema: []schema.GroupVersionKind{
62+
{
63+
Group: "",
64+
Version: "v1",
65+
Kind: "ServiceAccount",
66+
},
67+
},
68+
},
69+
{
70+
name: "double same object",
71+
inputObjects: &manifest.Objects{
72+
Items: []*manifest.Object{
73+
saObj1,
74+
saObj1,
75+
},
76+
},
77+
expectedSchema: []schema.GroupVersionKind{
78+
{
79+
Group: "",
80+
Version: "v1",
81+
Kind: "ServiceAccount",
82+
},
83+
},
84+
},
85+
{
86+
name: "double same type of object",
87+
inputObjects: &manifest.Objects{
88+
Items: []*manifest.Object{
89+
saObj1,
90+
saObj2,
3691
},
3792
},
38-
expectSchema: []schema.GroupVersionKind{
93+
expectedSchema: []schema.GroupVersionKind{
3994
{
4095
Group: "",
4196
Version: "v1",
4297
Kind: "ServiceAccount",
4398
},
4499
},
45100
},
101+
{
102+
name: "multiple objects",
103+
inputObjects: &manifest.Objects{
104+
Items: []*manifest.Object{
105+
dpObj1,
106+
saObj2,
107+
},
108+
},
109+
expectedSchema: []schema.GroupVersionKind{
110+
{
111+
Group: "",
112+
Version: "v1",
113+
Kind: "ServiceAccount",
114+
},
115+
{
116+
Group: "apps",
117+
Version: "v1",
118+
Kind: "Deployment",
119+
},
120+
},
121+
},
122+
{
123+
name: "empty objects",
124+
inputObjects: &manifest.Objects{
125+
Items: []*manifest.Object{},
126+
},
127+
expectedSchema: nil,
128+
},
46129
}
47130

48131
for _, tt := range tests {
49132
t.Run(tt.name, func(t *testing.T) {
50133
actualSchema := uniqueGroupVersionKind(tt.inputObjects)
51-
assert.Equal(t, tt.expectSchema, actualSchema)
134+
assert.Equal(t, tt.expectedSchema, actualSchema)
52135
})
53136
}
54137
}

0 commit comments

Comments
 (0)