Skip to content

Commit

Permalink
Add default virt storage class tests
Browse files Browse the repository at this point in the history
Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
  • Loading branch information
arnongilboa committed Dec 25, 2024
1 parent 2fd2089 commit 5d60ff1
Showing 1 changed file with 58 additions and 22 deletions.
80 changes: 58 additions & 22 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,31 @@ var tests = map[string]struct {
},
expectedErr: checkup.ErrNoDefaultStorageClass,
},
"onlyDefaultStorageClass": {
clientConfig: clientConfig{onlyDefaultStorageClass: true},
expectedResults: map[string]string{reporter.DefaultStorageClassKey: testScName2},
expectedErr: "",
},
"onlyDefaultVirtStorageClass": {
clientConfig: clientConfig{onlyDefaultVirtStorageClass: true},
expectedResults: map[string]string{reporter.DefaultStorageClassKey: testScName},
expectedErr: "",
},
"bothDefaultStorageClasses": {
clientConfig: clientConfig{bothDefaultStorageClasses: true},
expectedResults: map[string]string{reporter.DefaultStorageClassKey: testScName},
expectedErr: "",
},
"multipleDefaultStorageClasses": {
clientConfig: clientConfig{multipleDefaultStorageClasses: true},
expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrMultipleDefaultStorageClasses},
expectedErr: checkup.ErrMultipleDefaultStorageClasses,
},
"multipleDefaultVirtStorageClasses": {
clientConfig: clientConfig{multipleDefaultVirtStorageClasses: true},
expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrMultipleDefaultStorageClasses},
expectedErr: checkup.ErrMultipleDefaultStorageClasses,
},
"failPvcBound": {
clientConfig: clientConfig{failPvcBound: true},
expectedResults: map[string]string{reporter.PVCBoundKey: checkup.ErrPvcNotBound},
Expand Down Expand Up @@ -257,20 +277,24 @@ func successfulRunResults(vmiUnderTestName string) map[string]string {
}

type clientConfig struct {
skipDeletion bool
noStorageClasses bool
noDefaultStorageClass bool
multipleDefaultStorageClasses bool
failPvcBound bool
unsetEfsStorageClass bool
spIncomplete bool
noVolumeSnapshotClasses bool
dicNoDataSource bool
dataSourceNotReady bool
expectNoVMI bool
cloneFallback bool
failMigration bool
singleNode bool
skipDeletion bool
noStorageClasses bool
noDefaultStorageClass bool
onlyDefaultStorageClass bool
onlyDefaultVirtStorageClass bool
bothDefaultStorageClasses bool
multipleDefaultStorageClasses bool
multipleDefaultVirtStorageClasses bool
failPvcBound bool
unsetEfsStorageClass bool
spIncomplete bool
noVolumeSnapshotClasses bool
dicNoDataSource bool
dataSourceNotReady bool
expectNoVMI bool
cloneFallback bool
failMigration bool
singleNode bool
}

type clientStub struct {
Expand Down Expand Up @@ -465,29 +489,41 @@ func (cs *clientStub) ListStorageClasses(ctx context.Context) (*storagev1.Storag
Items: []storagev1.StorageClass{
{
ObjectMeta: metav1.ObjectMeta{
Name: testScName,
Annotations: map[string]string{checkup.AnnDefaultStorageClass: "true"},
Name: testScName,
Annotations: map[string]string{
checkup.AnnDefaultVirtStorageClass: checkup.StrTrue,
checkup.AnnDefaultStorageClass: checkup.StrFalse,
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: testScName2,
Annotations: map[string]string{checkup.AnnDefaultStorageClass: "false"},
Name: testScName2,
Annotations: map[string]string{
checkup.AnnDefaultVirtStorageClass: checkup.StrFalse,
checkup.AnnDefaultStorageClass: checkup.StrTrue,
},
},
},
},
}
if cs.noDefaultStorageClass {
scList.Items[0].Annotations[checkup.AnnDefaultStorageClass] = "false"
if cs.onlyDefaultStorageClass || cs.noDefaultStorageClass {
scList.Items[0].Annotations[checkup.AnnDefaultVirtStorageClass] = checkup.StrFalse
}
if cs.onlyDefaultVirtStorageClass || cs.noDefaultStorageClass {
scList.Items[1].Annotations[checkup.AnnDefaultStorageClass] = checkup.StrFalse
}
if cs.multipleDefaultStorageClasses {
scList.Items[1].Annotations[checkup.AnnDefaultStorageClass] = "true"
scList.Items[0].Annotations[checkup.AnnDefaultStorageClass] = checkup.StrTrue
}
if cs.multipleDefaultVirtStorageClasses {
scList.Items[1].Annotations[checkup.AnnDefaultVirtStorageClass] = checkup.StrTrue
}
if cs.unsetEfsStorageClass {
scList.Items = append(scList.Items, storagev1.StorageClass{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sc-unset-efs",
Annotations: map[string]string{checkup.AnnDefaultStorageClass: "false"},
Annotations: map[string]string{checkup.AnnDefaultStorageClass: checkup.StrFalse},
},
Provisioner: efsSc,
Parameters: map[string]string{"uid": ""},
Expand Down

0 comments on commit 5d60ff1

Please sign in to comment.