Skip to content

Commit

Permalink
Fixing the UT failure in the driver code
Browse files Browse the repository at this point in the history
Signed-off-by: meghana_gm <meghana.gm@dell.com>
  • Loading branch information
meggm committed Sep 4, 2024
1 parent 4b25d92 commit ff6fef4
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions pkg/drivers/powerflex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,86 @@ var (
{"empty config", csmForPowerFlex("empty"), powerFlexClient, shared.MakeSecretWithJSON("empty-config", pFlexNS, configJSONFileEmpty), "Arrays details are not provided"},
{"bad config", csmForPowerFlex("bad"), powerFlexClient, shared.MakeSecretWithJSON("bad-config", pFlexNS, configJSONFileBad), "unable to parse"},
}

modifyPowerflexCRTests = []struct {
name string
yamlString string
cr csmv1.ContainerStorageModule
fileType string
expected string
}{
{
name: "Controller case with values",
yamlString: "CSI_HEALTH_MONITOR_ENABLED=OLD CSI_POWERFLEX_EXTERNAL_ACCESS=OLD CSI_DEBUG=OLD",
cr: csmv1.ContainerStorageModule{
Spec: csmv1.ContainerStorageModuleSpec{
Driver: csmv1.Driver{
Controller: csmv1.ContainerTemplate{
Envs: []corev1.EnvVar{
{Name: "X_CSI_POWERFLEX_EXTERNAL_ACCESS", Value: "NEW_POWERFLEX_ACCESS"},
{Name: "X_CSI_HEALTH_MONITOR_ENABLED", Value: "NEW_HEALTH_MONITOR"},
{Name: "X_CSI_DEBUG", Value: "NEW_DEBUG"},
},
},
},
},
},
fileType: "Controller",
expected: "CSI_HEALTH_MONITOR_ENABLED=OLD CSI_POWERFLEX_EXTERNAL_ACCESS=OLD CSI_DEBUG=OLD",
},
{
name: "Node case with values",
yamlString: "CSI_APPROVE_SDC_ENABLED=NEW_APPROVE_SDC CSI_RENAME_SDC_ENABLED=NEW_RENAME_SDC CSI_PREFIX_RENAME_SDC=NEW_RENAME_PREFIX CSI_VXFLEXOS_MAX_VOLUMES_PER_NODE=NEW_MAX_VOLUMES CSI_HEALTH_MONITOR_ENABLED=NEW_HEALTH_MONITOR_NODE CSI_DEBUG=NEW_DEBUG",
cr: csmv1.ContainerStorageModule{
Spec: csmv1.ContainerStorageModuleSpec{
Driver: csmv1.Driver{
Node: csmv1.ContainerTemplate{
Envs: []corev1.EnvVar{
{Name: "X_CSI_APPROVE_SDC_ENABLED", Value: "NEW_APPROVE_SDC"},
{Name: "X_CSI_RENAME_SDC_ENABLED", Value: "NEW_RENAME_SDC"},
{Name: "X_CSI_PREFIX_RENAME_SDC", Value: "NEW_RENAME_PREFIX"},
{Name: "X_CSI_VXFLEXOS_MAX_VOLUMES_PER_NODE", Value: "NEW_MAX_VOLUMES"},
{Name: "X_CSI_HEALTH_MONITOR_ENABLED", Value: "NEW_HEALTH_MONITOR_NODE"},
{Name: "X_CSI_DEBUG", Value: "NEW_DEBUG"},
},
},
},
},
},
fileType: "Node",
expected: "CSI_APPROVE_SDC_ENABLED=NEW_APPROVE_SDC CSI_RENAME_SDC_ENABLED=NEW_RENAME_SDC CSI_PREFIX_RENAME_SDC=NEW_RENAME_PREFIX CSI_VXFLEXOS_MAX_VOLUMES_PER_NODE=NEW_MAX_VOLUMES CSI_HEALTH_MONITOR_ENABLED=NEW_HEALTH_MONITOR_NODE CSI_DEBUG=NEW_DEBUG",
},
{
name: "CSIDriverSpec case with storage capacity",
yamlString: "CSI_STORAGE_CAPACITY_ENABLED=OLD CSI_VXFLEXOS_QUOTA_ENABLED=OLD",
cr: csmv1.ContainerStorageModule{
Spec: csmv1.ContainerStorageModuleSpec{
Driver: csmv1.Driver{
CSIDriverSpec: csmv1.CSIDriverSpec{
StorageCapacity: true,
},
},
},
},
fileType: "CSIDriverSpec",
expected: "CSI_STORAGE_CAPACITY_ENABLED=OLD CSI_VXFLEXOS_QUOTA_ENABLED=OLD",
},
{
name: "CSIDriverSpec case without storage capacity",
yamlString: "CSI_STORAGE_CAPACITY_ENABLED=OLD CSI_VXFLEXOS_QUOTA_ENABLED=OLD",
cr: csmv1.ContainerStorageModule{
Spec: csmv1.ContainerStorageModuleSpec{
Driver: csmv1.Driver{
CSIDriverSpec: csmv1.CSIDriverSpec{
StorageCapacity: false,
},
},
},
},
fileType: "CSIDriverSpec",
expected: "CSI_STORAGE_CAPACITY_ENABLED=OLD CSI_VXFLEXOS_QUOTA_ENABLED=OLD",
},
}
)

func TestPowerFlexGo(t *testing.T) {
Expand Down Expand Up @@ -94,3 +174,12 @@ func csmForPowerFlexBadVersion() csmv1.ContainerStorageModule {

return res
}

func TestModifyPowerflexCR(t *testing.T) {
for _, tt := range modifyPowerflexCRTests {
t.Run(tt.name, func(t *testing.T) {
result := ModifyPowerflexCR(tt.yamlString, tt.cr, tt.fileType)
assert.Equal(t, tt.expected, result)
})
}
}

0 comments on commit ff6fef4

Please sign in to comment.