Skip to content

Commit

Permalink
Unit test fixes after controller-runtime update to v0.16.0
Browse files Browse the repository at this point in the history
Fixed the TestCreateSCCs & TestOcsProviderServerEnsureCreated tests.
No longer skip the TestOCSProviderServerStorageClassRequest test.

Signed-off-by: Malay Kumar Parida <[email protected]>
  • Loading branch information
malayparida2000 committed Nov 15, 2023
1 parent bf415a6 commit fa1a0e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/storagecluster/provider_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions services/provider/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fa1a0e6

Please sign in to comment.