Skip to content

Commit

Permalink
Update tests to be compatible with CR > v0.10.0
Browse files Browse the repository at this point in the history
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 <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Nov 30, 2021
1 parent eeb7823 commit 9c0f131
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions controllers/update_test.go
Expand Up @@ -232,6 +232,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
Expand Down Expand Up @@ -528,13 +529,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())
Expand Down

0 comments on commit 9c0f131

Please sign in to comment.