@@ -136,34 +136,71 @@ func TestStepDeleteExisting(t *testing.T) {
136
136
func TestCheckResource (t * testing.T ) {
137
137
for _ , test := range []struct {
138
138
testName string
139
- actual runtime.Object
139
+ actual [] runtime.Object
140
140
expected runtime.Object
141
141
shouldError bool
142
142
}{
143
143
{
144
144
testName : "resource matches" ,
145
- actual : testutils .NewPod ("hello" , "" ),
145
+ actual : []runtime.Object {
146
+ testutils .NewPod ("hello" , "" ),
147
+ },
146
148
expected : testutils .NewPod ("hello" , "" ),
147
149
},
150
+ {
151
+ testName : "resource matches with labels" ,
152
+ actual : []runtime.Object {
153
+ testutils .WithSpec (t , testutils .NewPod ("deploy-8b2d" , "" ),
154
+ map [string ]interface {}{
155
+ "containers" : nil ,
156
+ "serviceAccountName" : "invalid" ,
157
+ }),
158
+ testutils .WithSpec (
159
+ t ,
160
+ testutils .WithLabels (
161
+ t ,
162
+ testutils .NewPod ("deploy-8c2z" , "" ),
163
+ map [string ]string {"label" : "my-label" },
164
+ ),
165
+ map [string ]interface {}{
166
+ "containers" : nil ,
167
+ "serviceAccountName" : "valid" ,
168
+ },
169
+ ),
170
+ },
171
+
172
+ expected : testutils .WithSpec (
173
+ t ,
174
+ testutils .WithLabels (
175
+ t ,
176
+ testutils .NewPod ("" , "" ),
177
+ map [string ]string {"label" : "my-label" },
178
+ ),
179
+ map [string ]interface {}{
180
+ "containers" : nil ,
181
+ "serviceAccountName" : "valid" ,
182
+ },
183
+ ),
184
+ },
148
185
{
149
186
testName : "resource mis-match" ,
150
- actual : testutils .NewPod ("hello" , "" ),
187
+ actual : []runtime. Object { testutils .NewPod ("hello" , "" )} ,
151
188
expected : testutils .WithSpec (t , testutils .NewPod ("hello" , "" ), map [string ]interface {}{"invalid" : "key" }),
152
189
shouldError : true ,
153
190
},
154
191
{
155
192
testName : "resource subset match" ,
156
- actual : testutils .WithSpec (t , testutils .NewPod ("hello" , "" ), map [string ]interface {}{
193
+ actual : []runtime. Object { testutils .WithSpec (t , testutils .NewPod ("hello" , "" ), map [string ]interface {}{
157
194
"containers" : nil ,
158
195
"restartPolicy" : "OnFailure" ,
159
- }),
196
+ })} ,
160
197
expected : testutils .WithSpec (t , testutils .NewPod ("hello" , "" ), map [string ]interface {}{
161
198
"restartPolicy" : "OnFailure" ,
162
199
}),
163
200
},
164
201
{
165
202
testName : "resource does not exist" ,
166
- actual : testutils .NewPod ("other" , "" ),
203
+ actual : []runtime. Object { testutils .NewPod ("other" , "" )} ,
167
204
expected : testutils .NewPod ("hello" , "" ),
168
205
shouldError : true ,
169
206
},
@@ -174,19 +211,20 @@ func TestCheckResource(t *testing.T) {
174
211
fakeDiscovery := testutils .FakeDiscoveryClient ()
175
212
namespace := testNamespace
176
213
177
- _ , _ , err := testutils .Namespaced (fakeDiscovery , test .actual , namespace )
178
- assert .Nil (t , err )
214
+ for _ , actualObj := range test .actual {
215
+ _ , _ , err := testutils .Namespaced (fakeDiscovery , actualObj , namespace )
216
+ assert .Nil (t , err )
217
+ }
179
218
180
219
step := Step {
181
220
Logger : testutils .NewTestLogger (t , "" ),
182
221
Client : func (bool ) (client.Client , error ) {
183
- return fake .NewClientBuilder ().WithScheme (scheme .Scheme ).WithRuntimeObjects (test .actual ).Build (), nil
222
+ return fake .NewClientBuilder ().WithScheme (scheme .Scheme ).WithRuntimeObjects (test .actual ... ).Build (), nil
184
223
},
185
224
DiscoveryClient : func () (discovery.DiscoveryInterface , error ) { return fakeDiscovery , nil },
186
225
}
187
226
188
227
errors := step .CheckResource (test .expected , namespace )
189
-
190
228
if test .shouldError {
191
229
assert .NotEqual (t , []error {}, errors )
192
230
} else {
0 commit comments