Skip to content

Commit edb3461

Browse files
committed
Update tests to be compatible with CR > v0.10.0
In controller-runtime v0.10.0, the client is updated to clean any stale data in the target object when performing any operation. This results in test failure for the code that constructs an object with both spec and status, and creates the object and updates status it with the same object. The fix is to set the status separately on the object before updating it. Refer: kubernetes-sigs/controller-runtime#1640 Signed-off-by: Sunny <[email protected]>
1 parent 675a01d commit edb3461

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

controllers/update_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ Images:
229229
policy.Name = policyKey.Name
230230
policy.Namespace = policyKey.Namespace
231231
g.Expect(testEnv.Create(ctx, policy)).To(Succeed())
232+
policy.Status.LatestImage = "helloworld:v1.0.0"
232233
g.Expect(testEnv.Status().Update(ctx, policy)).To(Succeed())
233234

234235
// Format the expected message given the generated values
@@ -525,13 +526,11 @@ func TestImageUpdateAutomation_e2e(t *testing.T) {
525526
},
526527
},
527528
},
528-
Status: imagev1_reflect.ImagePolicyStatus{
529-
LatestImage: latestImage,
530-
},
531529
}
532530
policy.Name = policyKey.Name
533531
policy.Namespace = policyKey.Namespace
534532
g.Expect(testEnv.Create(ctx, policy)).To(Succeed())
533+
policy.Status.LatestImage = latestImage
535534
g.Expect(testEnv.Status().Update(ctx, policy)).To(Succeed())
536535
defer func() {
537536
g.Expect(testEnv.Delete(ctx, policy)).To(Succeed())

0 commit comments

Comments
 (0)