Skip to content

Commit

Permalink
Unit tests for Node Topologies (#358)
Browse files Browse the repository at this point in the history
* Adding Unit tests

* fixing formatting issues
  • Loading branch information
harshitap26 authored and falfaroc committed Dec 18, 2024
1 parent bc79b28 commit 49b41c9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
14 changes: 13 additions & 1 deletion service/features/service.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,20 @@ Feature: VxFlex OS CSI interface
| "volume1" | "multi_az" | "none" |
| "volume1" | "invalid_multi_az" | "no zone topology found in accessibility requirements" |

Scenario: Call NodeGetInfo without zone label
Given a VxFlexOS service
And I use config "config"
When I call NodeGetInfo
Then a NodeGetInfo is returned without zone topology

Scenario: Call NodeGetInfo with zone label
Given a VxFlexOS service
And I use config "multi_az"
When I call NodeGetInfo with zone labels
Then a valid NodeGetInfo is returned with node topology
Then a valid NodeGetInfo is returned with node topology

Scenario: Call NodeGetInfo with zone label with invalid config
Given a VxFlexOS service
And I use config "invalid_multi_az"
When I call NodeGetInfo with zone labels
Then a NodeGetInfo is returned without zone system topology
26 changes: 25 additions & 1 deletion service/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,7 @@ func (f *feature) iCallNodeGetInfo() error {
req := new(csi.NodeGetInfoRequest)
f.service.opts.SdcGUID = "9E56672F-2F4B-4A42-BFF4-88B6846FBFDA"
GetNodeLabels = mockGetNodeLabels
GetNodeUID = mockGetNodeUID
f.nodeGetInfoResponse, f.err = f.service.NodeGetInfo(*ctx, req)
return nil
}
Expand Down Expand Up @@ -4727,7 +4728,7 @@ func (f *feature) iCallCreateVolumeWithZones(name string) error {
}

func mockGetNodeLabelsWithZone(_ context.Context, _ *service) (map[string]string, error) {
labels := map[string]string{"zone.csi-vxflexos.dellemc.com": "zoneA"}
labels := map[string]string{"zone." + Name: "zoneA"}
return labels, nil
}

Expand All @@ -4750,6 +4751,27 @@ func (f *feature) aValidNodeGetInfoIsReturnedWithNodeTopology() error {
return nil
}

func (f *feature) aNodeGetInfoIsReturnedWithoutZoneTopology() error {
accessibility := f.nodeGetInfoResponse.GetAccessibleTopology()
Log.Printf("Node Accessibility %+v", accessibility)
if _, ok := accessibility.Segments["zone."+Name]; ok {
return fmt.Errorf("zone found")
}
return nil
}

func (f *feature) aNodeGetInfoIsReturnedWithoutZoneSystemTopology() error {
accessibility := f.nodeGetInfoResponse.GetAccessibleTopology()
Log.Printf("Node Accessibility %+v", accessibility)

for _, array := range f.service.opts.arrays {
if _, ok := accessibility.Segments[Name+"/"+array.SystemID]; ok {
return fmt.Errorf("zone found")
}
}
return nil
}

func FeatureContext(s *godog.ScenarioContext) {
f := &feature{}
s.Step(`^a VxFlexOS service$`, f.aVxFlexOSService)
Expand Down Expand Up @@ -4977,6 +4999,8 @@ func FeatureContext(s *godog.ScenarioContext) {
s.Step(`^I call CreateVolume "([^"]*)" with zones$`, f.iCallCreateVolumeWithZones)
s.Step(`^I call NodeGetInfo with zone labels$`, f.iCallNodeGetInfoWithZoneLabels)
s.Step(`^a valid NodeGetInfo is returned with node topology$`, f.aValidNodeGetInfoIsReturnedWithNodeTopology)
s.Step(`^a NodeGetInfo is returned without zone topology$`, f.aNodeGetInfoIsReturnedWithoutZoneTopology)
s.Step(`^a NodeGetInfo is returned without zone system topology$`, f.aNodeGetInfoIsReturnedWithoutZoneSystemTopology)

s.After(func(ctx context.Context, _ *godog.Scenario, _ error) (context.Context, error) {
if f.server != nil {
Expand Down

0 comments on commit 49b41c9

Please sign in to comment.