@@ -134,8 +134,9 @@ func TestProcess_matchScenarios(t *testing.T) {
134
134
tests := []struct {
135
135
name string
136
136
137
- param * deployapi.DeploymentTriggerImageChangeParams
138
- notFound bool
137
+ param * deployapi.DeploymentTriggerImageChangeParams
138
+ containerImageFunc func () string
139
+ notFound bool
139
140
140
141
expected bool
141
142
}{
@@ -212,6 +213,23 @@ func TestProcess_matchScenarios(t *testing.T) {
212
213
213
214
expected : false ,
214
215
},
216
+ {
217
+ name : "allow lastTriggeredImage to resolve" ,
218
+
219
+ containerImageFunc : func () string {
220
+ image := "registry:5000/openshift/test-image-stream@sha256:0000000000000000000000000000000000000000000000000000000000000001"
221
+ return image
222
+ },
223
+ param : & deployapi.DeploymentTriggerImageChangeParams {
224
+ Automatic : true ,
225
+ ContainerNames : []string {"container1" },
226
+ From : kapi.ObjectReference {Name : imageapi .JoinImageStreamTag (deploytest .ImageStreamName , imageapi .DefaultImageTag )},
227
+ LastTriggeredImage : "" ,
228
+ },
229
+ notFound : false ,
230
+
231
+ expected : true ,
232
+ },
215
233
}
216
234
217
235
for i := range tests {
@@ -237,17 +255,26 @@ func TestProcess_matchScenarios(t *testing.T) {
237
255
},
238
256
}
239
257
258
+ if test .containerImageFunc != nil {
259
+ config .Spec .Template .Spec .Containers [0 ].Image = test .containerImageFunc ()
260
+ }
240
261
image := config .Spec .Template .Spec .Containers [0 ].Image
241
262
242
263
err := processTriggers (config , fake , false , nil )
243
264
if err != nil {
244
265
t .Errorf ("unexpected error: %v" , err )
245
266
continue
246
267
}
247
- if test .expected && config .Spec .Template .Spec .Containers [0 ].Image == image {
268
+ if test .containerImageFunc == nil && test . expected && config .Spec .Template .Spec .Containers [0 ].Image == image {
248
269
t .Errorf ("%s: expected an image update but got none" , test .name )
249
- } else if ! test .expected && config .Spec .Template .Spec .Containers [0 ].Image != image {
270
+ continue
271
+ }
272
+ if ! test .expected && config .Spec .Template .Spec .Containers [0 ].Image != image {
250
273
t .Errorf ("%s: didn't expect an image update but got %s" , test .name , image )
274
+ continue
275
+ }
276
+ if test .containerImageFunc != nil && image != config .Spec .Triggers [0 ].ImageChangeParams .LastTriggeredImage {
277
+ t .Errorf ("%s: expected a lastTriggeredImage update to %q, got none" , test .name , image )
251
278
}
252
279
}
253
280
}
0 commit comments