Skip to content

Commit

Permalink
added test for NodeGetVolumeStats
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasha-dell committed Nov 18, 2024
1 parent fc72b2e commit 36fea1c
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"testing"

"github.com/onsi/ginkgo/reporters"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/dell/csi-powerstore/v2/mocks"
Expand Down Expand Up @@ -4365,3 +4367,78 @@ func getNodeVolumeExpandValidRequest(volid string, isBlock bool) *csi.NodeExpand
}
return &req
}

func TestNodeGetVolumeStats(t *testing.T) {
setVariables()

ctx := context.Background()

tests := []struct {
name string
req *csi.NodeGetVolumeStatsRequest
setupMocks func()
expectedErr error
}{
{
name: "missing volume ID",
req: &csi.NodeGetVolumeStatsRequest{
VolumePath: validTargetPath,
},
setupMocks: func() {},
expectedErr: status.Error(codes.InvalidArgument, "no volume ID provided"),
},
{
name: "missing volume path",
req: &csi.NodeGetVolumeStatsRequest{
VolumeId: validBlockVolumeID,
},
setupMocks: func() {},
expectedErr: status.Error(codes.InvalidArgument, "no volume Path provided"),
},
{
name: "successful volume stats retrieval",
req: &csi.NodeGetVolumeStatsRequest{
VolumeId: validBlockVolumeID,
VolumePath: validTargetPath,
},
setupMocks: func() {
clientMock.On("GetCluster", mock.Anything).Return(gopowerstore.Cluster{
Name: validClusterName,
NVMeNQN: validNVMEInitiators[0],
}, nil)
clientMock.On("GetVolume", mock.Anything, mock.Anything).Return(gopowerstore.Volume{
Description: "",
ID: validBlockVolumeID,
Name: "name",
Size: controller.MaxVolumeSizeBytes / 200,
}, nil)
clientMock.On("GetHostVolumeMappingByVolumeID", mock.Anything, mock.Anything).Return([]gopowerstore.HostVolumeMapping{
{
HostGroupID: "validHostGroupID",
HostID: "validHostID",
ID: "id",
LogicalUnitNumber: 0,
VolumeID: "validVolID",
},
}, nil)
clientMock.On("GetHost", mock.Anything, mock.Anything).Return(gopowerstore.Host{
Name: "host-name",
}, nil)
},
expectedErr: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.setupMocks()
resp, err := nodeSvc.NodeGetVolumeStats(ctx, tt.req)
if err != nil && err.Error() != tt.expectedErr.Error() {
t.Errorf("expected error %v, got %v", tt.expectedErr, err)
}
if err == nil && resp == nil {
t.Errorf("expected response, got nil")
}
})
}
}

0 comments on commit 36fea1c

Please sign in to comment.