@@ -28,6 +28,7 @@ import (
28
28
"google.golang.org/grpc/status"
29
29
30
30
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-09-01/storage"
31
+ "github.com/Azure/go-autorest/autorest/to"
31
32
"github.com/container-storage-interface/spec/lib/go/csi"
32
33
"github.com/golang/mock/gomock"
33
34
"github.com/stretchr/testify/assert"
@@ -89,8 +90,8 @@ func (c *mockBlobClient) GetContainer(ctx context.Context, subsID, resourceGroup
89
90
return storage.BlobContainer {ContainerProperties : c .conProp }, nil
90
91
}
91
92
92
- func NewMockBlobClient (errorType errType , custom string , conProp storage.ContainerProperties ) * mockBlobClient {
93
- return & mockBlobClient {errorType : & errorType , custom : & custom , conProp : & conProp }
93
+ func NewMockBlobClient (errorType * errType , custom * string , conProp * storage.ContainerProperties ) * mockBlobClient {
94
+ return & mockBlobClient {errorType : errorType , custom : custom , conProp : conProp }
94
95
}
95
96
96
97
//creates and returns mock storage account client
@@ -909,6 +910,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
909
910
{
910
911
name : "volume ID missing" ,
911
912
req : & csi.ValidateVolumeCapabilitiesRequest {},
913
+ clientErr : NULL ,
912
914
containerProp : nil ,
913
915
expectedRes : nil ,
914
916
expectedErr : status .Error (codes .InvalidArgument , "Volume ID missing in request" ),
@@ -918,6 +920,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
918
920
req : & csi.ValidateVolumeCapabilitiesRequest {
919
921
VolumeId : "unit-test" ,
920
922
},
923
+ clientErr : NULL ,
921
924
containerProp : nil ,
922
925
expectedRes : nil ,
923
926
expectedErr : status .Error (codes .InvalidArgument , "volume capabilities missing in request" ),
@@ -928,6 +931,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
928
931
VolumeId : "unit-test" ,
929
932
VolumeCapabilities : blockVolumeCapabilities ,
930
933
},
934
+ clientErr : NULL ,
931
935
containerProp : nil ,
932
936
expectedRes : nil ,
933
937
expectedErr : status .Error (codes .InvalidArgument , "block volume capability not supported" ),
@@ -938,6 +942,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
938
942
VolumeId : "unit-test" ,
939
943
VolumeCapabilities : stdVolumeCapabilities ,
940
944
},
945
+ clientErr : NULL ,
941
946
containerProp : nil ,
942
947
expectedRes : nil ,
943
948
expectedErr : status .Error (codes .NotFound , "error parsing volume id: \" unit-test\" , should at least contain two #" ),
@@ -952,6 +957,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
952
957
defaultSecretAccountKey : "b" ,
953
958
},
954
959
},
960
+ clientErr : NULL ,
955
961
containerProp : nil ,
956
962
expectedRes : nil ,
957
963
expectedErr : status .Error (codes .Internal , "azure: base storage service url required" ),
@@ -1032,7 +1038,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
1032
1038
1033
1039
for _ , test := range testCases {
1034
1040
res , err := d .ValidateVolumeCapabilities (context .Background (), test .req )
1035
- d .cloud .BlobClient = & mockBlobClient { errorType : & test .clientErr , conProp : test .containerProp }
1041
+ d .cloud .BlobClient = NewMockBlobClient ( & test .clientErr , to . StringPtr ( "" ), test .containerProp )
1036
1042
assert .Equal (t , test .expectedErr , err , "Error in testcase (%s): Errors must match" , test .name )
1037
1043
assert .Equal (t , test .expectedRes , res , "Error in testcase (%s): Response must match" , test .name )
1038
1044
}
@@ -1265,8 +1271,9 @@ func TestCreateBlobContainer(t *testing.T) {
1265
1271
1266
1272
d := NewFakeDriver ()
1267
1273
d .cloud = & azure.Cloud {}
1274
+ conProp := & storage.ContainerProperties {}
1268
1275
for _ , test := range tests {
1269
- d .cloud .BlobClient = NewMockBlobClient (test .clientErr , test .customErrStr , storage. ContainerProperties {} )
1276
+ d .cloud .BlobClient = NewMockBlobClient (& test .clientErr , & test .customErrStr , conProp )
1270
1277
err := d .CreateBlobContainer (context .Background (), test .subsID , test .rg , test .accountName , test .containerName , test .secrets )
1271
1278
if ! reflect .DeepEqual (err , test .expectedErr ) {
1272
1279
t .Errorf ("test(%s), actualErr: (%v), expectedErr: (%v)" , test .desc , err , test .expectedErr )
@@ -1336,8 +1343,9 @@ func TestDeleteBlobContainer(t *testing.T) {
1336
1343
d := NewFakeDriver ()
1337
1344
d .cloud = & azure.Cloud {}
1338
1345
1346
+ connProp := & storage.ContainerProperties {}
1339
1347
for _ , test := range tests {
1340
- d .cloud .BlobClient = NewMockBlobClient (test .clientErr , test .customErrStr , storage. ContainerProperties {} )
1348
+ d .cloud .BlobClient = NewMockBlobClient (& test .clientErr , & test .customErrStr , connProp )
1341
1349
err := d .DeleteBlobContainer (context .Background (), test .subsID , test .rg , test .accountName , test .containerName , test .secrets )
1342
1350
if ! reflect .DeepEqual (err , test .expectedErr ) {
1343
1351
t .Errorf ("test(%s), actualErr: (%v), expectedErr: (%v)" , test .desc , err , test .expectedErr )
0 commit comments