From 96af457474066b526f532a37eed9f84412c25d7b Mon Sep 17 00:00:00 2001 From: Raghavendra Talur Date: Mon, 19 Apr 2021 13:17:53 -0400 Subject: [PATCH] tests: use fake objects provided by the fake client The fake client stores the objects after adding a resource version to them. This is a breaking change introduced in https://github.com/kubernetes-sigs/controller-runtime/pull/1306. Therefore we cannot use the fake object that we provided as input to the the fake client and should use the object obtained from the Get operation. Signed-off-by: Raghavendra Talur --- .../ocsinitialization_controller_test.go | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/controllers/ocsinitialization/ocsinitialization_controller_test.go b/controllers/ocsinitialization/ocsinitialization_controller_test.go index fd03953f70..d0fee11a26 100644 --- a/controllers/ocsinitialization/ocsinitialization_controller_test.go +++ b/controllers/ocsinitialization/ocsinitialization_controller_test.go @@ -50,14 +50,17 @@ func getTestParams(mockNamespace bool, t *testing.T) (v1.OCSInitialization, reco Namespace: request.Namespace, }, } - ocsRecon := v1.OCSInitialization{ - ObjectMeta: metav1.ObjectMeta{ - Name: request.Name, - Namespace: request.Namespace, - }, - } - return ocs, request, getReconciler(t, &ocsRecon) + reconciler := getReconciler(t, &ocs) + //The fake client stores the objects after adding a resource version to + //them. This is a breaking change introduced in + //https://github.com/kubernetes-sigs/controller-runtime/pull/1306. + //Therefore we cannot use the fake object that we provided as input to the + //the fake client and should use the object obtained from the Get + //operation. + _ = reconciler.Client.Get(context.TODO(), request.NamespacedName, &ocs) + + return ocs, request, reconciler } func getReconciler(t *testing.T, objs ...client.Object) OCSInitializationReconciler { @@ -230,9 +233,8 @@ func TestCreateSCCs(t *testing.T) { if tc.sscCreated { ocs.Status.SCCsCreated = false - // TODO: uncomment this! - //err := reconciler.Client.Update(context.TODO(), &ocs) - //assert.NoErrorf(t, err, "[%s]: failed to update ocsInit status", tc.label) + err := reconciler.Client.Update(context.TODO(), &ocs) + assert.NoErrorf(t, err, "[%s]: failed to update ocsInit status", tc.label) } _, err := reconciler.Reconcile(context.TODO(), request)