From fa1a0e684627cef4d99400408d47dc6d4225a5da Mon Sep 17 00:00:00 2001 From: Malay Kumar Parida Date: Wed, 15 Nov 2023 00:34:19 +0530 Subject: [PATCH] Unit test fixes after controller-runtime update to v0.16.0 Fixed the TestCreateSCCs & TestOcsProviderServerEnsureCreated tests. No longer skip the TestOCSProviderServerStorageClassRequest test. Signed-off-by: Malay Kumar Parida --- .../ocsinitialization_controller_test.go | 2 +- controllers/storagecluster/provider_server_test.go | 8 ++++---- services/provider/server/server_test.go | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/controllers/ocsinitialization/ocsinitialization_controller_test.go b/controllers/ocsinitialization/ocsinitialization_controller_test.go index b92f2bb8f5..fa6f923d66 100644 --- a/controllers/ocsinitialization/ocsinitialization_controller_test.go +++ b/controllers/ocsinitialization/ocsinitialization_controller_test.go @@ -240,7 +240,7 @@ func TestCreateSCCs(t *testing.T) { if tc.sccCreated { ocs.Status.SCCsCreated = true - err := reconciler.Client.Update(context.TODO(), &ocs) + err := reconciler.Client.Status().Update(context.TODO(), &ocs) assert.NoErrorf(t, err, "[%s]: failed to update ocsInit status", tc.label) } diff --git a/controllers/storagecluster/provider_server_test.go b/controllers/storagecluster/provider_server_test.go index 054dc38cbd..e410bea9e8 100644 --- a/controllers/storagecluster/provider_server_test.go +++ b/controllers/storagecluster/provider_server_test.go @@ -43,7 +43,7 @@ func TestOcsProviderServerEnsureCreated(t *testing.T) { Hostname: "fake", }, } - err = r.Update(context.TODO(), service) + err = r.Status().Update(context.TODO(), service) assert.NoError(t, err) // call ensureCreated again after filling the status of svc, It will fail on deployment now @@ -58,7 +58,7 @@ func TestOcsProviderServerEnsureCreated(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: ocsProviderServerName}, } deployment.Status.AvailableReplicas = 1 - err = r.Update(context.TODO(), deployment) + err = r.Status().Update(context.TODO(), deployment) assert.NoError(t, err) // call ensureCreated again after filling the status of deployment, It will pass now @@ -106,7 +106,7 @@ func TestOcsProviderServerEnsureCreated(t *testing.T) { Hostname: "fake", }, } - err = r.Update(context.TODO(), service) + err = r.Status().Update(context.TODO(), service) assert.NoError(t, err) // call ensureCreated again after filling the status of svc, It will fail on deployment now @@ -121,7 +121,7 @@ func TestOcsProviderServerEnsureCreated(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: ocsProviderServerName}, } deployment.Status.AvailableReplicas = 1 - err = r.Update(context.TODO(), deployment) + err = r.Status().Update(context.TODO(), deployment) assert.NoError(t, err) // call ensureCreated again after filling the status of deployment, It will pass now diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index a263032a0c..1263ceb208 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -371,16 +371,11 @@ func createCephClientAndSecret(name string, server *OCSProviderServer) (*rookCep } func TestOCSProviderServerStorageClassRequest(t *testing.T) { - // TODO: Fix this test by migrating unit tests from fake client to envtest.Environment with a real client and API - // Skipping the test as with new controller-runtime v0.15.0 the fake client will panic if initialized with an object that has a DeletionTimestamp and no finalizer - // https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.15.0#:~:text=Update%20fake%20client,the%20kube%2Dapiserver - t.Skip("Skipping TestOCSProviderServerStorageClassRequest") claimNameUnderDeletion := "claim-under-deletion" claimResourceUnderDeletion := &ocsv1alpha1.StorageClassRequest{ ObjectMeta: metav1.ObjectMeta{ Name: getStorageClassRequestName(string(consumerResource.UID), claimNameUnderDeletion), Namespace: serverNamespace, - DeletionTimestamp: &metav1.Time{}, }, Spec: ocsv1alpha1.StorageClassRequestSpec{ Type: "block",