@@ -134,8 +134,9 @@ func TestProcess_matchScenarios(t *testing.T) {
134134 tests := []struct {
135135 name string
136136
137- param * deployapi.DeploymentTriggerImageChangeParams
138- notFound bool
137+ param * deployapi.DeploymentTriggerImageChangeParams
138+ containerImageFunc func () string
139+ notFound bool
139140
140141 expected bool
141142 }{
@@ -212,6 +213,23 @@ func TestProcess_matchScenarios(t *testing.T) {
212213
213214 expected : false ,
214215 },
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+ },
215233 }
216234
217235 for i := range tests {
@@ -237,17 +255,26 @@ func TestProcess_matchScenarios(t *testing.T) {
237255 },
238256 }
239257
258+ if test .containerImageFunc != nil {
259+ config .Spec .Template .Spec .Containers [0 ].Image = test .containerImageFunc ()
260+ }
240261 image := config .Spec .Template .Spec .Containers [0 ].Image
241262
242263 err := processTriggers (config , fake , false , nil )
243264 if err != nil {
244265 t .Errorf ("unexpected error: %v" , err )
245266 continue
246267 }
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 {
248269 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 {
250273 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 )
251278 }
252279 }
253280}
0 commit comments