From f415d86eb966e6459c0074b25297fe44de7c06f8 Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 1 Oct 2021 21:57:29 +0530 Subject: [PATCH] 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: https://github.com/kubernetes-sigs/controller-runtime/pull/1640 Signed-off-by: Sunny --- controllers/update_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/controllers/update_test.go b/controllers/update_test.go index 18ee099d..d2b3f153 100644 --- a/controllers/update_test.go +++ b/controllers/update_test.go @@ -229,6 +229,7 @@ Images: policy.Name = policyKey.Name policy.Namespace = policyKey.Namespace g.Expect(testEnv.Create(ctx, policy)).To(Succeed()) + policy.Status.LatestImage = "helloworld:v1.0.0" g.Expect(testEnv.Status().Update(ctx, policy)).To(Succeed()) // Format the expected message given the generated values @@ -525,13 +526,11 @@ func TestImageUpdateAutomation_e2e(t *testing.T) { }, }, }, - Status: imagev1_reflect.ImagePolicyStatus{ - LatestImage: latestImage, - }, } policy.Name = policyKey.Name policy.Namespace = policyKey.Namespace g.Expect(testEnv.Create(ctx, policy)).To(Succeed()) + policy.Status.LatestImage = latestImage g.Expect(testEnv.Status().Update(ctx, policy)).To(Succeed()) defer func() { g.Expect(testEnv.Delete(ctx, policy)).To(Succeed())