@@ -56,7 +56,9 @@ func TestCreateVolume(t *testing.T) {
56
56
Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER ,
57
57
},
58
58
}
59
- extraTags = "key1=value1,key2=value2"
59
+ extraTags = "key1=value1,key2=value2"
60
+ emptyExtraTags = ""
61
+ invalidExtraTags = "key1=value1,value2"
60
62
)
61
63
testCases := []struct {
62
64
name string
@@ -374,6 +376,111 @@ func TestCreateVolume(t *testing.T) {
374
376
mockCtl .Finish ()
375
377
},
376
378
},
379
+ {
380
+ name : "success: empty extraTags" ,
381
+ testFunc : func (t * testing.T ) {
382
+ mockCtl := gomock .NewController (t )
383
+ mockCloud := mocks .NewMockCloud (mockCtl )
384
+
385
+ driver := controllerService {
386
+ cloud : mockCloud ,
387
+ inFlight : internal .NewInFlight (),
388
+ driverOptions : & DriverOptions {},
389
+ }
390
+
391
+ req := & csi.CreateVolumeRequest {
392
+ Name : volumeName ,
393
+ VolumeCapabilities : []* csi.VolumeCapability {
394
+ stdVolCap ,
395
+ },
396
+ Parameters : map [string ]string {
397
+ volumeParamsSubnetId : subnetId ,
398
+ volumeParamsSecurityGroupIds : securityGroupIds ,
399
+ volumeParamsExtraTags : emptyExtraTags ,
400
+ },
401
+ }
402
+
403
+ ctx := context .Background ()
404
+ fs := & cloud.FileSystem {
405
+ FileSystemId : fileSystemId ,
406
+ CapacityGiB : volumeSizeGiB ,
407
+ DnsName : dnsName ,
408
+ MountName : mountName ,
409
+ }
410
+ mockCloud .EXPECT ().CreateFileSystem (gomock .Eq (ctx ), gomock .Eq (volumeName ), gomock .Any ()).Return (fs , nil )
411
+ mockCloud .EXPECT ().WaitForFileSystemAvailable (gomock .Eq (ctx ), gomock .Eq (fileSystemId )).Return (nil )
412
+
413
+ resp , err := driver .CreateVolume (ctx , req )
414
+ if err != nil {
415
+ t .Fatalf ("CreateVolume is failed: %v" , err )
416
+ }
417
+
418
+ if resp .Volume == nil {
419
+ t .Fatal ("resp.Volume is nil" )
420
+ }
421
+
422
+ if resp .Volume .VolumeId != fileSystemId {
423
+ t .Fatalf ("VolumeId mismatches. actual: %v expected: %v" , resp .Volume .VolumeId , fileSystemId )
424
+ }
425
+
426
+ if resp .Volume .CapacityBytes == 0 {
427
+ t .Fatalf ("resp.Volume.CapacityGiB is zero" )
428
+ }
429
+
430
+ dnsname , exists := resp .Volume .VolumeContext [volumeContextDnsName ]
431
+ if ! exists {
432
+ t .Fatal ("dnsname is missing" )
433
+ }
434
+
435
+ if dnsname != dnsName {
436
+ t .Fatalf ("dnsname mismatches. actual: %v expected: %v" , dnsname , dnsName )
437
+ }
438
+
439
+ mountname , exists := resp .Volume .VolumeContext [volumeContextMountName ]
440
+ if ! exists {
441
+ t .Fatal ("mountname is missing" )
442
+ }
443
+
444
+ if mountname != mountName {
445
+ t .Fatalf ("mountname mismatches. actual: %v expected: %v" , mountname , mountName )
446
+ }
447
+
448
+ mockCtl .Finish ()
449
+ },
450
+ },
451
+ {
452
+ name : "fail: invalid extraTags" ,
453
+ testFunc : func (t * testing.T ) {
454
+ mockCtl := gomock .NewController (t )
455
+ mockCloud := mocks .NewMockCloud (mockCtl )
456
+
457
+ driver := controllerService {
458
+ cloud : mockCloud ,
459
+ inFlight : internal .NewInFlight (),
460
+ driverOptions : & DriverOptions {},
461
+ }
462
+
463
+ req := & csi.CreateVolumeRequest {
464
+ Name : volumeName ,
465
+ VolumeCapabilities : []* csi.VolumeCapability {
466
+ stdVolCap ,
467
+ },
468
+ Parameters : map [string ]string {
469
+ volumeParamsSubnetId : subnetId ,
470
+ volumeParamsSecurityGroupIds : securityGroupIds ,
471
+ volumeParamsExtraTags : invalidExtraTags ,
472
+ },
473
+ }
474
+
475
+ ctx := context .Background ()
476
+ _ , err := driver .CreateVolume (ctx , req )
477
+ if err == nil {
478
+ t .Fatal ("CreateVolume is not failed" )
479
+ }
480
+
481
+ mockCtl .Finish ()
482
+ },
483
+ },
377
484
{
378
485
name : "fail: volume name missing" ,
379
486
testFunc : func (t * testing.T ) {
0 commit comments