Skip to content

Commit

Permalink
chore: fix ut
Browse files Browse the repository at this point in the history
fix golint

test: skip go vet check on test file

fix

fix golint
  • Loading branch information
andyzhangx committed Nov 21, 2024
1 parent 739696b commit d002b8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeSta
return nil, status.Errorf(codes.Internal, "%v", err)
}
if cache != nil {
resp := cache.(csi.NodeGetVolumeStatsResponse)
resp := cache.(*csi.NodeGetVolumeStatsResponse)
klog.V(6).Infof("NodeGetVolumeStats: volume stats for volume %s path %s is cached", req.VolumeId, req.VolumePath)
return &resp, nil
return resp, nil
}

mc := metrics.NewMetricContext(blobCSIDriverName, "node_get_volume_stats", d.cloud.ResourceGroup, "", d.Name)
Expand Down Expand Up @@ -624,7 +624,7 @@ func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeSta
isOperationSucceeded = true
klog.V(6).Infof("NodeGetVolumeStats: volume stats for volume %s path %s is %v", req.VolumeId, req.VolumePath, resp)
// cache the volume stats per volume
d.volStatsCache.Set(req.VolumeId, *resp)
d.volStatsCache.Set(req.VolumeId, resp)
return resp, nil
}

Expand Down
42 changes: 21 additions & 21 deletions pkg/blob/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,37 +161,37 @@ func TestNodePublishVolume(t *testing.T) {
tests := []struct {
desc string
setup func(*Driver)
req csi.NodePublishVolumeRequest
req *csi.NodePublishVolumeRequest
expectedErr error
cleanup func(*Driver)
}{
{
desc: "Volume capabilities missing",
req: csi.NodePublishVolumeRequest{},
req: &csi.NodePublishVolumeRequest{},
expectedErr: status.Error(codes.InvalidArgument, "Volume capability missing in request"),
},
{
desc: "Volume ID missing",
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap}},
req: &csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap}},
expectedErr: status.Error(codes.InvalidArgument, "Volume ID missing in request"),
},
{
desc: "Stage path missing",
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
req: &csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
VolumeId: "vol_1",
TargetPath: sourceTest},
expectedErr: status.Error(codes.InvalidArgument, "Staging target not provided"),
},
{
desc: "Stage target path missing",
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
req: &csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
VolumeId: "vol_1",
StagingTargetPath: sourceTest},
expectedErr: status.Error(codes.InvalidArgument, "Target path not provided"),
},
{
desc: "Valid request read only",
req: csi.NodePublishVolumeRequest{
req: &csi.NodePublishVolumeRequest{
VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
VolumeId: "vol_1",
TargetPath: targetTest,
Expand All @@ -205,7 +205,7 @@ func TestNodePublishVolume(t *testing.T) {
},
{
desc: "Error creating directory",
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
req: &csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
VolumeId: "vol_1",
TargetPath: "./azure.go",
StagingTargetPath: sourceTest,
Expand All @@ -214,7 +214,7 @@ func TestNodePublishVolume(t *testing.T) {
},
{
desc: "Error mounting resource busy",
req: csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
req: &csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
VolumeId: "vol_1",
TargetPath: targetTest,
StagingTargetPath: sourceTest,
Expand All @@ -223,7 +223,7 @@ func TestNodePublishVolume(t *testing.T) {
},
{
desc: "[Error] invalid mountPermissions",
req: csi.NodePublishVolumeRequest{
req: &csi.NodePublishVolumeRequest{
VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
VolumeId: "vol_1",
TargetPath: targetTest,
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestNodePublishVolume(t *testing.T) {
if test.setup != nil {
test.setup(d)
}
_, err := d.NodePublishVolume(context.Background(), &test.req)
_, err := d.NodePublishVolume(context.Background(), test.req)

if !reflect.DeepEqual(err, test.expectedErr) {
t.Errorf("Desc: %s - Unexpected error: %v - Expected: %v", test.desc, err, test.expectedErr)
Expand Down Expand Up @@ -323,23 +323,23 @@ func TestNodeUnpublishVolume(t *testing.T) {
tests := []struct {
desc string
setup func(*Driver)
req csi.NodeUnpublishVolumeRequest
req *csi.NodeUnpublishVolumeRequest
expectedErr error
cleanup func(*Driver)
}{
{
desc: "Volume ID missing",
req: csi.NodeUnpublishVolumeRequest{TargetPath: targetTest},
req: &csi.NodeUnpublishVolumeRequest{TargetPath: targetTest},
expectedErr: status.Error(codes.InvalidArgument, "Volume ID missing in request"),
},
{
desc: "Target missing",
req: csi.NodeUnpublishVolumeRequest{VolumeId: "vol_1"},
req: &csi.NodeUnpublishVolumeRequest{VolumeId: "vol_1"},
expectedErr: status.Error(codes.InvalidArgument, "Target path missing in request"),
},
{
desc: "Valid request",
req: csi.NodeUnpublishVolumeRequest{TargetPath: "./abc.go", VolumeId: "vol_1"},
req: &csi.NodeUnpublishVolumeRequest{TargetPath: "./abc.go", VolumeId: "vol_1"},
expectedErr: nil,
},
}
Expand All @@ -360,7 +360,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
if test.setup != nil {
test.setup(d)
}
_, err := d.NodeUnpublishVolume(context.Background(), &test.req)
_, err := d.NodeUnpublishVolume(context.Background(), test.req)

if !reflect.DeepEqual(err, test.expectedErr) {
t.Errorf("Unexpected error: %v", err)
Expand Down Expand Up @@ -706,27 +706,27 @@ func TestNodeGetVolumeStats(t *testing.T) {

tests := []struct {
desc string
req csi.NodeGetVolumeStatsRequest
req *csi.NodeGetVolumeStatsRequest
expectedErr error
}{
{
desc: "[Error] Volume ID missing",
req: csi.NodeGetVolumeStatsRequest{VolumePath: targetTest},
req: &csi.NodeGetVolumeStatsRequest{VolumePath: targetTest},
expectedErr: status.Error(codes.InvalidArgument, "NodeGetVolumeStats volume ID was empty"),
},
{
desc: "[Error] VolumePath missing",
req: csi.NodeGetVolumeStatsRequest{VolumeId: "vol_1"},
req: &csi.NodeGetVolumeStatsRequest{VolumeId: "vol_1"},
expectedErr: status.Error(codes.InvalidArgument, "NodeGetVolumeStats volume path was empty"),
},
{
desc: "[Error] Incorrect volume path",
req: csi.NodeGetVolumeStatsRequest{VolumePath: nonexistedPath, VolumeId: "vol_1"},
req: &csi.NodeGetVolumeStatsRequest{VolumePath: nonexistedPath, VolumeId: "vol_1"},
expectedErr: status.Errorf(codes.NotFound, "path /not/a/real/directory does not exist"),
},
{
desc: "[Success] Standard success",
req: csi.NodeGetVolumeStatsRequest{VolumePath: fakePath, VolumeId: "vol_1"},
req: &csi.NodeGetVolumeStatsRequest{VolumePath: fakePath, VolumeId: "vol_1"},
expectedErr: nil,
},
}
Expand All @@ -736,7 +736,7 @@ func TestNodeGetVolumeStats(t *testing.T) {
d := NewFakeDriver()

for _, test := range tests {
_, err := d.NodeGetVolumeStats(context.Background(), &test.req)
_, err := d.NodeGetVolumeStats(context.Background(), test.req)
//t.Errorf("[debug] error: %v\n metrics: %v", err, metrics)
if !reflect.DeepEqual(err, test.expectedErr) {
t.Errorf("desc: %v, expected error: %v, actual error: %v", test.desc, test.expectedErr, err)
Expand Down

0 comments on commit d002b8f

Please sign in to comment.