Skip to content

Commit

Permalink
unit-test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Malay Kumar Parida <[email protected]>
  • Loading branch information
malayparida2000 committed Mar 6, 2024
1 parent 796dc4b commit 8504e6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
12 changes: 6 additions & 6 deletions controllers/storagecluster/cephfilesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,32 @@ func assertCephFileSystem(t *testing.T, reconciler StorageClusterReconciler, cr
assert.Equal(t, expectedAf[0].Spec, actualFs.Spec)
}

func TestCreateDefaultSubvolumeGroup(t *testing.T) {
func TestCreateSubvolumeGroups(t *testing.T) {
var objects []client.Object
t, reconciler, cr, _ := initStorageClusterResourceCreateUpdateTest(t, objects, nil)
filesystem, err := reconciler.newCephFilesystemInstances(cr)
assert.NoError(t, err)

err = reconciler.createDefaultSubvolumeGroup(filesystem[0].Name, filesystem[0].Namespace, filesystem[0].OwnerReferences)
err = reconciler.ensureCreateCephFilesystemSubVolumeGroups(filesystem[0])
assert.NoError(t, err)

svg := &cephv1.CephFilesystemSubVolumeGroup{}
expectedsvgName := generateNameForCephSubvolumeGroup(filesystem[0].Name)
expectedsvgName := getSubVolumeGroupsForFilesystem(filesystem[0])[0].Name
err = reconciler.Client.Get(context.TODO(), types.NamespacedName{Name: expectedsvgName, Namespace: filesystem[0].Namespace}, svg)
assert.NoError(t, err) // no error
}

func TestDeleteDefaultSubvolumeGroup(t *testing.T) {
func TestDeleteDefaultSubvolumeGroups(t *testing.T) {
var objects []client.Object
t, reconciler, cr, _ := initStorageClusterResourceCreateUpdateTest(t, objects, nil)
filesystem, err := reconciler.newCephFilesystemInstances(cr)
assert.NoError(t, err)

err = reconciler.deleteDefaultSubvolumeGroup(filesystem[0].Name, filesystem[0].Namespace)
err = reconciler.ensureDeleteCephFilesystemSubVolumeGroups(filesystem[0])
assert.NoError(t, err)

svg := &cephv1.CephFilesystemSubVolumeGroup{}
expectedsvgName := generateNameForCephSubvolumeGroup(filesystem[0].Name)
expectedsvgName := getSubVolumeGroupsForFilesystem(filesystem[0])[0].Name
err = reconciler.Client.Get(context.TODO(), types.NamespacedName{Name: expectedsvgName, Namespace: filesystem[0].Namespace}, svg)
assert.Error(t, err) // error as csi svg is deleted
}
Expand Down
11 changes: 10 additions & 1 deletion controllers/storagecluster/initialization_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ func createFakeInitializationStorageClusterReconciler(t *testing.T, obj ...runti
},
}

cfssvg := &cephv1.CephFilesystemSubVolumeGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "csi",
},
Status: &cephv1.CephFilesystemSubVolumeGroupStatus{
Phase: cephv1.ConditionType(util.PhaseReady),
},
}

infrastructure := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{Name: "cluster"},
}
Expand Down Expand Up @@ -360,7 +369,7 @@ func createFakeInitializationStorageClusterReconciler(t *testing.T, obj ...runti
}
}

runtimeObjects = append(runtimeObjects, mockNodeList.DeepCopy(), cbp, cfs, cnfs, cnfsbp, cnfssvc, infrastructure, networkConfig)
runtimeObjects = append(runtimeObjects, mockNodeList.DeepCopy(), cbp, cfs, cfssvg, cnfs, cnfsbp, cnfssvc, infrastructure, networkConfig)
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(runtimeObjects...).WithStatusSubresource(statusSubresourceObjs...).Build()

return StorageClusterReconciler{
Expand Down
11 changes: 10 additions & 1 deletion controllers/storagecluster/storagecluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,15 @@ func createFakeStorageClusterReconciler(t *testing.T, obj ...runtime.Object) Sto
Phase: cephv1.ConditionType(util.PhaseReady),
},
}
cfssvg := &cephv1.CephFilesystemSubVolumeGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "csi",
Namespace: namespace,
},
Status: &cephv1.CephFilesystemSubVolumeGroupStatus{
Phase: cephv1.ConditionType(util.PhaseReady),
},
}
cbp := &cephv1.CephBlockPool{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-cephblockpool", name),
Expand All @@ -1121,7 +1130,7 @@ func createFakeStorageClusterReconciler(t *testing.T, obj ...runtime.Object) Sto
Phase: cephv1.ConditionType(util.PhaseReady),
},
}
obj = append(obj, cbp, cfs)
obj = append(obj, cbp, cfs, cfssvg)
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(obj...).WithStatusSubresource(sc).Build()

clusters, err := util.GetClusters(context.TODO(), client)
Expand Down

0 comments on commit 8504e6d

Please sign in to comment.