Skip to content

Commit

Permalink
Upgrading unit test coverage (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
delldubey authored Nov 8, 2023
1 parent 068fdd8 commit 2728104
Show file tree
Hide file tree
Showing 8 changed files with 658 additions and 197 deletions.
417 changes: 313 additions & 104 deletions mock/mock.go

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions mock/symmetrix13.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"symmetrixId": "000000000013",
"local": true,
"model": "PowerMax_2500",
"microcode": "6079.175.0",
"microcode_date": "10-12-2023",
"microcode_registered_build": 268,
"microcode_package_version": "10.0.1.3 (HotFix 10108, Build 6079_175/0268, 2023-10-12 19:17:49)",
"cache_size_mb": 454656,
"fe_dir_count": 4,
"be_dir_count": 4,
"rdf_dir_count": 4,
"max_hyper_per_disk": 512,
"dev_masking_aclx_config": "Enabled",
"aclx_lun_addr": 0,
"config_change_state": "Enabled",
"disk_group_assignment": "In Use",
"raid_config": "RAID-5 (4+1)",
"pav_model": "DynamicStandardPAV",
"pav_alias_limit": 255,
"sddf_state": "Enabled",
"srdfa_max_throttle": 0,
"srdfa_cache_usage": 75,
"max_sys_slot": 1656000,
"max_dev_slot": 82800,
"last_ipl_time": "2023-02-20 16:34:27",
"last_fast_ipl_time": "2023-10-16 23:46:25",
"symm_alert": "11/39",
"service_level_rt_multiplier": "Default",
"fba_geo_emulation": "Native",
"cache_partition": "Disabled",
"disk_service_state": "Deferred",
"data_encryption": "Enabled",
"rep_cache_usage": 0,
"device_count": 15458,
"disk_count": 33,
"spare_disk_count": 1,
"unconfig_disk_count": 0,
"reliability_state": "Degraded-NoRebuild",
"all_flash": true,
"system_sized_property": [
{
"srp_name": "SRP_1",
"sized_fba_data_reduction_ratio": "4.0:1",
"sized_fba_capacity_tb": 1196,
"sized_fba_reducible_percent": 90
}
]
}
2 changes: 1 addition & 1 deletion replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (c *Client) DeleteStorageGroupSnapshot(ctx context.Context, symID string, s
if err != nil {
log.Error("Error in Delete Storage Group Snapshot: " + err.Error())
} else {
log.Info(fmt.Sprintf("Successfully deleted volume: %s", snapID))
log.Infof("Successfully deleted Storage Group Snapshot: %s", snapID)
}
return err
}
Expand Down
134 changes: 113 additions & 21 deletions unit_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type unitContext struct {
fileSystem *types.FileSystem
nfsExport *types.NFSExport
nasServer *types.NASServer
fileInterface *types.FileInterface
}

func (c *unitContext) reset() {
Expand Down Expand Up @@ -177,6 +178,7 @@ func (c *unitContext) reset() {
c.fileSystem = nil
c.nfsExport = nil
c.nasServer = nil
c.fileInterface = nil
}

func (c *unitContext) iInduceError(errorType string) error {
Expand Down Expand Up @@ -250,6 +252,18 @@ func (c *unitContext) iInduceError(errorType string) error {
mock.InducedErrors.CreateNFSExportError = false
mock.InducedErrors.UpdateNFSExportError = false
mock.InducedErrors.DeleteNFSExportError = false
mock.InducedErrors.GetFileInterfaceError = false
mock.InducedErrors.ExecuteActionError = false
mock.InducedErrors.CreateSnapshotPolicyError = false
mock.InducedErrors.GetStorageGroupSnapshotError = false
mock.InducedErrors.GetStorageGroupSnapshotSnapError = false
mock.InducedErrors.GetStorageGroupSnapshotSnapDetailError = false
mock.InducedErrors.GetStorageGroupSnapshotSnapModifyError = false
mock.InducedErrors.GetSnapshotPolicyError = false
mock.InducedErrors.GetSnapshotPolicyListError = false
mock.InducedErrors.CreateSnapshotPolicyError = false
mock.InducedErrors.ModifySnapshotPolicyError = false
mock.InducedErrors.DeleteSnapshotPolicyError = false
switch errorType {
case "InvalidJSON":
mock.InducedErrors.InvalidJSON = true
Expand Down Expand Up @@ -399,6 +413,8 @@ func (c *unitContext) iInduceError(errorType string) error {
mock.InducedErrors.GetRDFGroupError = true
case "GetSnapshotPolicyError":
mock.InducedErrors.GetSnapshotPolicyError = true
case "CreateSnapshotPolicyError":
mock.InducedErrors.CreateSnapshotPolicyError = true
case "GetSnapshotPolicyListError":
mock.InducedErrors.GetSnapshotPolicyListError = true
case "ModifySnapshotPolicyError":
Expand Down Expand Up @@ -433,6 +449,10 @@ func (c *unitContext) iInduceError(errorType string) error {
mock.InducedErrors.UpdateNFSExportError = true
case "DeleteNFSExportError":
mock.InducedErrors.DeleteNFSExportError = true
case "GetFileInterfaceError":
mock.InducedErrors.GetFileInterfaceError = true
case "ExecuteActionError":
mock.InducedErrors.ExecuteActionError = true
case "none":
default:
return fmt.Errorf("unknown errorType: %s", errorType)
Expand Down Expand Up @@ -1644,6 +1664,22 @@ func (c *unitContext) iCallGetStorageGroupSnapshotsWith(storageGroupID string) e
return nil
}

func (c *unitContext) iCallGetStorageGroupSnapshotsWithAndParam(storageGroupID, params string) error {
var exludeManualSnaps bool
var exludeSlSnaps bool
param := strings.Split(params, ",")
for _, p := range param {
if p == "exludeManualSnaps" {
exludeManualSnaps = true
}
if p == "exludeSlSnaps" {
exludeSlSnaps = true
}
}
c.sgSnapshot, c.err = c.client.GetStorageGroupSnapshots(context.TODO(), symID, storageGroupID, exludeManualSnaps, exludeSlSnaps)
return nil
}

func (c *unitContext) iCallCreateStorageGroupSnapshotWith(storageGroupID string) error {
c.storageGroupSnap, c.err = c.client.CreateStorageGroupSnapshot(context.TODO(), symID, storageGroupID, c.storageGroupSnapSetting)
return nil
Expand Down Expand Up @@ -1843,11 +1879,16 @@ func (c *unitContext) iCallUpdateHostName(newName string) error {
return nil
}

func (c *unitContext) iCallCreateSGReplica() error {
func (c *unitContext) iCallCreateSGReplica(mode string) error {
localSG, remoteSG := mock.DefaultStorageGroup, mock.DefaultStorageGroup // Using same names for local and remote storage groups
remoteServiceLevel := mock.DefaultServiceLevel // Using the same service level as local
rdfgNumber := fmt.Sprintf("%d", mock.DefaultRDFGNo)
_, c.err = c.client.CreateSGReplica(context.TODO(), symID, mock.DefaultRemoteSymID, srdfMode, rdfgNumber, localSG, remoteSG, remoteServiceLevel, false)
var rdfgNumber string
if mode == "METRO" {
rdfgNumber = fmt.Sprintf("%d", mock.DefaultMetroRDFGNo)
} else {
rdfgNumber = fmt.Sprintf("%d", mock.DefaultAsyncRDFGNo)
}
_, c.err = c.client.CreateSGReplica(context.TODO(), symID, mock.DefaultRemoteSymID, mode, rdfgNumber, localSG, remoteSG, remoteServiceLevel, false)
return nil
}

Expand Down Expand Up @@ -1885,11 +1926,11 @@ func (c *unitContext) theVolumesShouldBeReplicated(compliment string) error {

func (c *unitContext) iCallGetStorageGroupRDFInfo() error {
var sgrdf *types.StorageGroupRDFG
sgrdf, c.err = c.client.GetStorageGroupRDFInfo(context.TODO(), symID, mock.DefaultStorageGroup, fmt.Sprintf("%d", mock.DefaultRemoteRDFGNo))
sgrdf, c.err = c.client.GetStorageGroupRDFInfo(context.TODO(), symID, mock.DefaultStorageGroup, fmt.Sprintf("%d", mock.DefaultAsyncRemoteRDFGNo))
if c.err == nil {
if sgrdf.SymmetrixID != symID ||
sgrdf.StorageGroupName != mock.DefaultStorageGroup ||
sgrdf.RdfGroupNumber != mock.DefaultRDFGNo {
sgrdf.RdfGroupNumber != mock.DefaultAsyncRDFGNo {
c.err = fmt.Errorf("the returned storage group doesn't contain proper details")
}
}
Expand All @@ -1901,7 +1942,7 @@ func (c *unitContext) iCallGetRDFDevicePairInfo() error {
localVolID := c.volIDList[0]
remoteVolID := c.volIDList[0]

devicePairInfo, c.err = c.client.GetRDFDevicePairInfo(context.TODO(), symID, fmt.Sprintf("%d", mock.DefaultRemoteRDFGNo), localVolID)
devicePairInfo, c.err = c.client.GetRDFDevicePairInfo(context.TODO(), symID, fmt.Sprintf("%d", mock.DefaultAsyncRemoteRDFGNo), localVolID)
if c.err == nil {
if devicePairInfo.LocalSymmID != symID || devicePairInfo.RemoteSymmID != mock.DefaultRemoteSymID ||
devicePairInfo.LocalVolumeName != localVolID || devicePairInfo.RemoteVolumeName != remoteVolID {
Expand All @@ -1927,25 +1968,29 @@ func (c *unitContext) iCallGetProtectedStorageGroup() error {

func (c *unitContext) iCallGetRDFGroup() error {
var rdfGroup *types.RDFGroup
rdfGroup, c.err = c.client.GetRDFGroupByID(context.TODO(), symID, fmt.Sprintf("%d", mock.DefaultRemoteRDFGNo))
rdfGroup, c.err = c.client.GetRDFGroupByID(context.TODO(), symID, fmt.Sprintf("%d", mock.DefaultAsyncRemoteRDFGNo))
if c.err == nil {
if !rdfGroup.Async || rdfGroup.RemoteSymmetrix != mock.DefaultRemoteSymID || rdfGroup.RdfgNumber != mock.DefaultRemoteRDFGNo {
if !rdfGroup.Async || rdfGroup.RemoteSymmetrix != mock.DefaultRemoteSymID || rdfGroup.RdfgNumber != mock.DefaultAsyncRemoteRDFGNo {
c.err = fmt.Errorf("rdf group with incorrect details returned")
}
}
return nil
}

func (c *unitContext) iCallAddVolumesToProtectedStorageGroup() error {
c.err = c.client.AddVolumesToProtectedStorageGroup(context.TODO(), symID, mock.DefaultProtectedStorageGroup, mock.DefaultRemoteSymID, mock.DefaultProtectedStorageGroup, false, c.volIDList...)
func (c *unitContext) iCallAddVolumesToProtectedStorageGroup(mode string) error {
if mode == "ASYNC" {
c.err = c.client.AddVolumesToProtectedStorageGroup(context.TODO(), symID, mock.DefaultASYNCProtectedSG, mock.DefaultRemoteSymID, mock.DefaultASYNCProtectedSG, false, c.volIDList...)
} else {
c.err = c.client.AddVolumesToProtectedStorageGroup(context.TODO(), symID, mock.DefaultMETROProtectedSG, mock.DefaultRemoteSymID, mock.DefaultMETROProtectedSG, false, c.volIDList...)
}
return nil
}

func (c *unitContext) iCallCreateVolumeInProtectedStorageGroupSWithNameAndSize(volumeName string, sizeInCylinders int) error {
volOpts := make(map[string]interface{})
volOpts["capacityUnit"] = "CYL"
volOpts["enableMobility"] = "false"
c.vol, c.err = c.client.CreateVolumeInProtectedStorageGroupS(context.TODO(), symID, mock.DefaultRemoteSymID, mock.DefaultProtectedStorageGroup, mock.DefaultProtectedStorageGroup, volumeName, sizeInCylinders, volOpts)
c.vol, c.err = c.client.CreateVolumeInProtectedStorageGroupS(context.TODO(), symID, mock.DefaultRemoteSymID, mock.DefaultASYNCProtectedSG, mock.DefaultASYNCProtectedSG, volumeName, sizeInCylinders, volOpts)
return nil
}

Expand All @@ -1954,13 +1999,17 @@ func (c *unitContext) iCallRemoveVolumesFromProtectedStorageGroup() error {
return nil
}

func (c *unitContext) iCallCreateRDFPair() error {
_, c.err = c.client.CreateRDFPair(context.TODO(), symID, fmt.Sprintf("%d", mock.DefaultRDFGNo), c.volIDList[0], ASYNC, "", false, false)
func (c *unitContext) iCallCreateRDFPair(mode string) error {
if mode == "ASYNC" {
_, c.err = c.client.CreateRDFPair(context.TODO(), symID, fmt.Sprintf("%d", mock.DefaultAsyncRDFGNo), c.volIDList[0], mode, "", false, false)
} else {
_, c.err = c.client.CreateRDFPair(context.TODO(), symID, fmt.Sprintf("%d", mock.DefaultMetroRDFGNo), c.volIDList[0], mode, "", false, false)
}
return nil
}

func (c *unitContext) iCallExecuteAction(action string) error {
c.err = c.client.ExecuteReplicationActionOnSG(context.TODO(), symID, action, mock.DefaultStorageGroup, fmt.Sprintf("%d", mock.DefaultRDFGNo), false, false, false)
c.err = c.client.ExecuteReplicationActionOnSG(context.TODO(), symID, action, mock.DefaultASYNCProtectedSG, fmt.Sprintf("%d", mock.DefaultAsyncRDFGNo), false, false, true)
return nil
}

Expand Down Expand Up @@ -2025,9 +2074,9 @@ func (c *unitContext) iCallExecuteCreateRDFGroup() error {
PortWWN: "5000097200007003",
},
}
createRDFgPayload.Label = mock.DefaultRDFLabel
createRDFgPayload.LocalRDFNum = mock.DefaultRDFGNo
createRDFgPayload.RemoteRDFNum = mock.DefaultRemoteRDFGNo
createRDFgPayload.Label = mock.DefaultAsyncRDFLabel
createRDFgPayload.LocalRDFNum = mock.DefaultAsyncRDFGNo
createRDFgPayload.RemoteRDFNum = mock.DefaultAsyncRemoteRDFGNo
c.err = c.client.ExecuteCreateRDFGroup(context.TODO(), mock.DefaultSymmetrixID, createRDFgPayload)
return nil
}
Expand Down Expand Up @@ -2239,6 +2288,24 @@ func (c *unitContext) iCallCreateSnapshotPolicyWith(snapshotPolicyID string) err
return nil
}

func (c *unitContext) iCallCreateSnapshotPolicyWithAndPayload(snapshotPolicyID, payload string) error {
opPayload := make(map[string]interface{})
if payload == "cloudSnapshotPolicyDetails" {
opPayload["cloudSnapshotPolicyDetails"] = &types.CloudSnapshotPolicyDetails{
CloudRetentionDays: 1,
CloudProviderName: "emc",
}
}
if payload == "localSnapshotPolicyDetails" {
opPayload["localSnapshotPolicyDetails"] = &types.LocalSnapshotPolicyDetails{
Secure: true,
SnapshotCount: 1,
}
}
c.snapshotPolicy, c.err = c.client.CreateSnapshotPolicy(context.TODO(), symID, snapshotPolicyID, "1 Hour", 10, 2, 2, opPayload)
return nil
}

func (c *unitContext) iShouldGetSnapshotPolicytInformationIfNoError() error {
if c.err != nil {
return nil
Expand Down Expand Up @@ -2352,6 +2419,12 @@ func (c *unitContext) iCallGetNASServerListWithParam() error {
return nil
}

func (c *unitContext) iCallGetNFSExportListWithParam() error {
query := types.QueryParams{queryName: "nfs-1"}
c.nfsExportList, c.err = c.client.GetNFSExportList(context.TODO(), symID, query)
return nil
}

func (c *unitContext) iCallGetNFSExportList() error {
c.nfsExportList, c.err = c.client.GetNFSExportList(context.TODO(), symID, nil)
return nil
Expand Down Expand Up @@ -2483,6 +2556,20 @@ func (c *unitContext) iGetAValidNFSExportObjectIfNoError() error {
return nil
}

func (c *unitContext) iCallGetFileInterfaceByID(interfaceID string) error {
c.fileInterface, c.err = c.client.GetFileInterfaceByID(context.TODO(), symID, interfaceID)
return nil
}

func (c *unitContext) iGetAValidFileInterfaceObjectIfNoError() error {
if c.err == nil {
if c.fileInterface == nil {
return fmt.Errorf("file interface nil")
}
}
return nil
}

func UnitTestContext(s *godog.ScenarioContext) {
c := &unitContext{}
s.Step(`^I induce error "([^"]*)"$`, c.iInduceError)
Expand Down Expand Up @@ -2608,6 +2695,7 @@ func UnitTestContext(s *godog.ScenarioContext) {

// SG Snapshot
s.Step(`^I call GetStorageGroupSnapshots with "([^"]*)"$`, c.iCallGetStorageGroupSnapshotsWith)
s.Step(`^I call GetStorageGroupSnapshots with "([^"]*)" and param "([^"]*)"$`, c.iCallGetStorageGroupSnapshotsWithAndParam)
s.Step(`^I should get storage group snapshot information if no error$`, c.iShouldGetStorageGroupSnapshotInformationIfNoError)
s.Step(`^I call CreateStorageGroupSnapshot with "([^"]*)"$`, c.iCallCreateStorageGroupSnapshotWith)
s.Step(`^I call GetStorageGroupSnapshotSnapIds with "([^"]*)" and "([^"]*)"$`, c.iCallGetStorageGroupSnapshotSnapIdsWithAnd)
Expand Down Expand Up @@ -2643,19 +2731,19 @@ func UnitTestContext(s *godog.ScenarioContext) {
s.Step(`^I recieve (\d+) targets$`, c.iRecieveTargets)
s.Step(`^there should be no errors$`, c.thereShouldBeNoErrors)
s.Step(`^I call UpdateHostName "([^"]*)"$`, c.iCallUpdateHostName)

// SRDF
s.Step(`^I call CreateSGReplica$`, c.iCallCreateSGReplica)
s.Step(`^I call CreateSGReplica with "([^"]*)"$`, c.iCallCreateSGReplica)
s.Step(`^then SG should be replicated$`, c.thenSGShouldBeReplicated)
s.Step(`^I call GetStorageGroupRDFInfo$`, c.iCallGetStorageGroupRDFInfo)
s.Step(`^I call GetStorageGroupRDFInfo$`, c.iCallGetStorageGroupRDFInfo)
s.Step(`^I call GetRDFDevicePairInfo$`, c.iCallGetRDFDevicePairInfo)
s.Step(`^I call GetProtectedStorageGroup$`, c.iCallGetProtectedStorageGroup)
s.Step(`^I call GetRDFGroup$`, c.iCallGetRDFGroup)
s.Step(`^I call AddVolumesToProtectedStorageGroup$`, c.iCallAddVolumesToProtectedStorageGroup)
s.Step(`^I call AddVolumesToProtectedStorageGroup with "([^"]*)"$`, c.iCallAddVolumesToProtectedStorageGroup)
s.Step(`^I call CreateVolumeInProtectedStorageGroupS with name "([^"]*)" and size (\d+)$`, c.iCallCreateVolumeInProtectedStorageGroupSWithNameAndSize)
s.Step(`^the volumes should "([^"]*)" be replicated$`, c.theVolumesShouldBeReplicated)
s.Step(`^I call RemoveVolumesFromProtectedStorageGroup$`, c.iCallRemoveVolumesFromProtectedStorageGroup)
s.Step(`^I call CreateRDFPair$`, c.iCallCreateRDFPair)
s.Step(`^I call CreateRDFPair with "([^"]*)"$`, c.iCallCreateRDFPair)
s.Step(`^I call ExecuteAction "([^"]*)"$`, c.iCallExecuteAction)

// Performance Metrics
Expand All @@ -2679,6 +2767,7 @@ func UnitTestContext(s *godog.ScenarioContext) {

// Snapshot Policy
s.Step(`^I call CreateSnapshotPolicy with "([^"]*)"$`, c.iCallCreateSnapshotPolicyWith)
s.Step(`^I call CreateSnapshotPolicy with "([^"]*)" and payload "([^"]*)"$`, c.iCallCreateSnapshotPolicyWithAndPayload)
s.Step(`^I call GetSnapshotPolicy with "([^"]*)"$`, c.iCallGetSnapshotPolicyWith)
s.Step(`^I should get snapshot policy information if no error$`, c.iShouldGetSnapshotPolicytInformationIfNoError)
s.Step(`^I call ModifySnapshotPolicy with "([^"]*)" and "([^"]*)" and "([^"]*)"$`, c.iCallModifySnapshotPolicyWithAndAnd)
Expand Down Expand Up @@ -2711,4 +2800,7 @@ func UnitTestContext(s *godog.ScenarioContext) {
s.Step(`^I get a valid NFSExport object if no error$`, c.iGetAValidNFSExportObjectIfNoError)
s.Step(`^I call GetFileSystemListWithParam$`, c.iCallGetFileSystemListWithParam)
s.Step(`^I call GetNASServerListWithParam$`, c.iCallGetNASServerListWithParam)
s.Step(`^I call GetNFSExportListWithParam`, c.iCallGetNFSExportListWithParam)
s.Step(`^I call GetFileInterfaceByID "([^"]*)"$`, c.iCallGetFileInterfaceByID)
s.Step(`^I get a valid fileInterface Object if no error$`, c.iGetAValidFileInterfaceObjectIfNoError)
}
Loading

0 comments on commit 2728104

Please sign in to comment.