@@ -151,13 +151,29 @@ func TestReconcilerUpdate(t *testing.T) {
151151 delta .Add ("Spec.A" , "val1" , "val2" )
152152
153153 desired , desiredRTObj , _ := resourceMocks ()
154+ desired .On ("ReplaceConditions" , []* ackv1alpha1.Condition {}).Return ()
154155
155156 ids := & ackmocks.AWSResourceIdentifiers {}
156157 ids .On ("ARN" ).Return (& arn )
157158
158159 latest , latestRTObj , _ := resourceMocks ()
159160 latest .On ("Identifiers" ).Return (ids )
161+
162+ // resourceReconciler.ensureConditions will ensure that if the resource
163+ // manager has not set any Conditions on the resource, that at least an
164+ // ACK.ResourceSynced condition with status Unknown will be set on the
165+ // resource.
160166 latest .On ("Conditions" ).Return ([]* ackv1alpha1.Condition {})
167+ latest .On (
168+ "ReplaceConditions" ,
169+ mock .AnythingOfType ("[]*v1alpha1.Condition" ),
170+ ).Return ().Run (func (args mock.Arguments ) {
171+ conditions := args .Get (0 ).([]* ackv1alpha1.Condition )
172+ assert .Equal (t , 1 , len (conditions ))
173+ cond := conditions [0 ]
174+ assert .Equal (t , cond .Type , ackv1alpha1 .ConditionTypeResourceSynced )
175+ assert .Equal (t , cond .Status , corev1 .ConditionUnknown )
176+ })
161177
162178 rm := & ackmocks.AWSResourceManager {}
163179 rm .On ("ReadOne" , ctx , desired ).Return (
@@ -207,13 +223,18 @@ func TestReconcilerUpdate_PatchMetadataAndSpec_DiffInMetadata(t *testing.T) {
207223 delta .Add ("Spec.A" , "val1" , "val2" )
208224
209225 desired , desiredRTObj , _ := resourceMocks ()
226+ desired .On ("ReplaceConditions" , []* ackv1alpha1.Condition {}).Return ()
210227
211228 ids := & ackmocks.AWSResourceIdentifiers {}
212229 ids .On ("ARN" ).Return (& arn )
213230
214231 latest , latestRTObj , latestMetaObj := resourceMocks ()
215232 latest .On ("Identifiers" ).Return (ids )
216233 latest .On ("Conditions" ).Return ([]* ackv1alpha1.Condition {})
234+ latest .On (
235+ "ReplaceConditions" ,
236+ mock .AnythingOfType ("[]*v1alpha1.Condition" ),
237+ ).Return ()
217238
218239 // Note the change in annotations
219240 latestMetaObj .SetAnnotations (map [string ]string {"a" : "b" })
@@ -261,13 +282,18 @@ func TestReconcilerUpdate_PatchMetadataAndSpec_DiffInSpec(t *testing.T) {
261282 delta .Add ("Spec.A" , "val1" , "val2" )
262283
263284 desired , desiredRTObj , _ := resourceMocks ()
285+ desired .On ("ReplaceConditions" , []* ackv1alpha1.Condition {}).Return ()
264286
265287 ids := & ackmocks.AWSResourceIdentifiers {}
266288 ids .On ("ARN" ).Return (& arn )
267289
268290 latest , latestRTObj , _ := resourceMocks ()
269291 latest .On ("Identifiers" ).Return (ids )
270292 latest .On ("Conditions" ).Return ([]* ackv1alpha1.Condition {})
293+ latest .On (
294+ "ReplaceConditions" ,
295+ mock .AnythingOfType ("[]*v1alpha1.Condition" ),
296+ ).Return ()
271297 // Note no change to metadata...
272298
273299 rmf , rd := managedResourceManagerFactoryMocks (desired , latest )
@@ -310,13 +336,18 @@ func TestReconcilerHandleReconcilerError_PatchStatus_Latest(t *testing.T) {
310336 delta .Add ("Spec.A" , "val1" , "val2" )
311337
312338 desired , desiredRTObj , _ := resourceMocks ()
339+ desired .On ("ReplaceConditions" , []* ackv1alpha1.Condition {}).Return ()
313340
314341 ids := & ackmocks.AWSResourceIdentifiers {}
315342 ids .On ("ARN" ).Return (& arn )
316343
317344 latest , latestRTObj , latestMetaObj := resourceMocks ()
318345 latest .On ("Identifiers" ).Return (ids )
319346 latest .On ("Conditions" ).Return ([]* ackv1alpha1.Condition {})
347+ latest .On (
348+ "ReplaceConditions" ,
349+ mock .AnythingOfType ("[]*v1alpha1.Condition" ),
350+ ).Return ()
320351
321352 latestMetaObj .SetAnnotations (map [string ]string {"a" : "b" })
322353
@@ -343,6 +374,7 @@ func TestReconcilerHandleReconcilerError_NoPatchStatus_NoLatest(t *testing.T) {
343374 ctx := context .TODO ()
344375
345376 desired , _ , _ := resourceMocks ()
377+ desired .On ("ReplaceConditions" , []* ackv1alpha1.Condition {}).Return ()
346378
347379 rmf , _ := managedResourceManagerFactoryMocks (desired , nil )
348380 r , kc := reconcilerMocks (rmf )
@@ -371,13 +403,18 @@ func TestReconcilerUpdate_ErrorInLateInitialization(t *testing.T) {
371403 delta .Add ("Spec.A" , "val1" , "val2" )
372404
373405 desired , desiredRTObj , _ := resourceMocks ()
406+ desired .On ("ReplaceConditions" , []* ackv1alpha1.Condition {}).Return ()
374407
375408 ids := & ackmocks.AWSResourceIdentifiers {}
376409 ids .On ("ARN" ).Return (& arn )
377410
378411 latest , latestRTObj , _ := resourceMocks ()
379412 latest .On ("Identifiers" ).Return (ids )
380413 latest .On ("Conditions" ).Return ([]* ackv1alpha1.Condition {})
414+ latest .On (
415+ "ReplaceConditions" ,
416+ mock .AnythingOfType ("[]*v1alpha1.Condition" ),
417+ ).Return ()
381418
382419 rm := & ackmocks.AWSResourceManager {}
383420 rm .On ("ReadOne" , ctx , desired ).Return (
@@ -423,6 +460,7 @@ func TestReconcilerUpdate_ResourceNotManaged(t *testing.T) {
423460 delta := ackcompare .NewDelta ()
424461
425462 desired , _ , _ := resourceMocks ()
463+ desired .On ("ReplaceConditions" , []* ackv1alpha1.Condition {}).Return ()
426464
427465 ids := & ackmocks.AWSResourceIdentifiers {}
428466 ids .On ("ARN" ).Return (& arn )
0 commit comments