From 35f1f13d4625e7b0fa226c8385dad9ea77ebe91f Mon Sep 17 00:00:00 2001 From: Malgorzata Dutka Date: Fri, 27 Oct 2023 06:16:39 -0400 Subject: [PATCH] add unit tests --- go.mod | 2 +- service/controller.go | 2 +- test/unit-test/unit_test.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 9bd2748c..6904aa14 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/dell/csi-unity go 1.21 require ( - github.com/container-storage-interface/spec v1.5.0 + github.com/container-storage-interface/spec v1.6.0 github.com/cucumber/godog v0.10.0 github.com/dell/dell-csi-extensions/podmon v1.2.0 github.com/dell/gobrick v1.9.0 diff --git a/service/controller.go b/service/controller.go index a4582bd6..94147901 100644 --- a/service/controller.go +++ b/service/controller.go @@ -556,7 +556,7 @@ func (s *service) getMaximumVolumeSize(ctx context.Context, arrayID string) int6 log.Debugf("GetMaxVolumeSize returning: %v for Array having GlobalId %s", err, arrayID) return 0 } - return maxVolumeSize + return maxVolumeSize.MaxVolumSizeContent.Limit } func (s *service) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { diff --git a/test/unit-test/unit_test.go b/test/unit-test/unit_test.go index 1e5c77e7..3e3efa73 100644 --- a/test/unit-test/unit_test.go +++ b/test/unit-test/unit_test.go @@ -41,6 +41,8 @@ type feature struct { createSnapshotResponse *csi.CreateSnapshotResponse deleteSnapshotRequest *csi.DeleteSnapshotRequest deleteSnapshotResponse *csi.DeleteSnapshotResponse + getCapacityRequest *csi.GetCapacityRequest + getCapacityResponse *csi.GetCapacityResponse capability *csi.VolumeCapability capabilities []*csi.VolumeCapability validateVolumeCapabilitiesRequest *csi.ValidateVolumeCapabilitiesRequest @@ -1242,6 +1244,35 @@ func (f *feature) nodeExpandVolume(volID, volPath string) error { return err } +func (f *feature) whenICallGetCapacity() { + ctx := context.Background() + client := csi.NewControllerClient(grpcClient) + + capability := new(csi.VolumeCapability) + mount := new(csi.VolumeCapability_MountVolume) + mountType := new(csi.VolumeCapability_Mount) + mountType.Mount = mount + capability.AccessType = mountType + accessMode := new(csi.VolumeCapability_AccessMode) + accessMode.Mode = csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER + capability.AccessMode = accessMode + f.capability = capability + capabilities := make([]*csi.VolumeCapability, 0) + capabilities = append(capabilities, capability) + + f.getCapacityRequest = &csi.GetCapacityRequest{VolumeCapabilities: capabilities} + response, err := client.GetCapacity(ctx, f.getCapacityRequest) + if err != nil { + fmt.Printf("GetCapacity %s:\n", err.Error()) + f.addError(err) + } + if err == nil { + fmt.Printf("Snapshot ID: %d \n", response.MaximumVolumeSize) + } + + f.getCapacityResponse = response +} + func FeatureContext(s *godog.Suite) { f := &feature{} s.Step(`^a CSI service$`, f.aCSIService)