From 5b1a74b20d9c44c60f8366072b65d6b60c5be4ba 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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/controllers/ocsinitialization/ocsinitialization_controller_test.go b/controllers/ocsinitialization/ocsinitialization_controller_test.go index 2de547867a..871cb5a4fa 100644 --- a/controllers/ocsinitialization/ocsinitialization_controller_test.go +++ b/controllers/ocsinitialization/ocsinitialization_controller_test.go @@ -57,7 +57,16 @@ func getTestParams(mockNamespace bool, t *testing.T) (v1.OCSInitialization, reco }, } - 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 {