Skip to content

Commit 413e1e2

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 a76397d commit 413e1e2

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

controllers/update_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,11 @@ Images:
225225
},
226226
},
227227
},
228-
Status: imagev1_reflect.ImagePolicyStatus{
229-
LatestImage: "helloworld:v1.0.0",
230-
},
231228
}
232229
policy.Name = policyKey.Name
233230
policy.Namespace = policyKey.Namespace
234231
g.Expect(testEnv.Create(ctx, policy)).To(Succeed())
232+
policy.Status.LatestImage = "helloworld:v1.0.0"
235233
g.Expect(testEnv.Status().Update(ctx, policy)).To(Succeed())
236234

237235
// Format the expected message given the generated values
@@ -528,13 +526,11 @@ func TestImageUpdateAutomation_e2e(t *testing.T) {
528526
},
529527
},
530528
},
531-
Status: imagev1_reflect.ImagePolicyStatus{
532-
LatestImage: latestImage,
533-
},
534529
}
535530
policy.Name = policyKey.Name
536531
policy.Namespace = policyKey.Namespace
537532
g.Expect(testEnv.Create(ctx, policy)).To(Succeed())
533+
policy.Status.LatestImage = latestImage
538534
g.Expect(testEnv.Status().Update(ctx, policy)).To(Succeed())
539535
defer func() {
540536
g.Expect(testEnv.Delete(ctx, policy)).To(Succeed())

0 commit comments

Comments
 (0)