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 Oct 19, 2021
1 parent 675a01d commit edb3461
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions controllers/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit edb3461

Please sign in to comment.