@@ -30,8 +30,11 @@ import (
30
30
"google.golang.org/grpc"
31
31
"google.golang.org/grpc/codes"
32
32
"google.golang.org/grpc/status"
33
+ "sigs.k8s.io/cloud-provider-azure/pkg/provider"
33
34
35
+ "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-02-01/storage"
34
36
"github.com/container-storage-interface/spec/lib/go/csi"
37
+ "github.com/golang/mock/gomock"
35
38
"github.com/stretchr/testify/assert"
36
39
37
40
mount "k8s.io/mount-utils"
@@ -235,6 +238,7 @@ func TestNodePublishVolume(t *testing.T) {
235
238
_ = makeDir (sourceTest )
236
239
_ = makeDir (targetTest )
237
240
d := NewFakeDriver ()
241
+ d .cloud = provider .GetTestCloud (gomock .NewController (t ))
238
242
fakeMounter := & fakeMounter {}
239
243
fakeExec := & testingexec.FakeExec {ExactOrder : true }
240
244
d .mounter = & mount.SafeFormatAndMount {
@@ -243,6 +247,7 @@ func TestNodePublishVolume(t *testing.T) {
243
247
}
244
248
245
249
for _ , test := range tests {
250
+ d .cloud .ResourceGroup = "rg"
246
251
if test .setup != nil {
247
252
test .setup (d )
248
253
}
@@ -456,6 +461,131 @@ func TestNodeStageVolume(t *testing.T) {
456
461
}
457
462
},
458
463
},
464
+ {
465
+ name : "[Error] Could not mount to target" ,
466
+ testFunc : func (t * testing.T ) {
467
+ req := & csi.NodeStageVolumeRequest {
468
+ VolumeId : "unit-test" ,
469
+ StagingTargetPath : "error_is_likely" ,
470
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
471
+ VolumeContext : map [string ]string {
472
+ mountPermissionsField : "0755" ,
473
+ },
474
+ }
475
+ d := NewFakeDriver ()
476
+ fakeMounter := & fakeMounter {}
477
+ fakeExec := & testingexec.FakeExec {}
478
+ d .mounter = & mount.SafeFormatAndMount {
479
+ Interface : fakeMounter ,
480
+ Exec : fakeExec ,
481
+ }
482
+ _ , err := d .NodeStageVolume (context .TODO (), req )
483
+ expectedErr := status .Error (codes .Internal , fmt .Sprintf ("Could not mount target %q: %v" , req .StagingTargetPath , fmt .Errorf ("fake IsLikelyNotMountPoint: fake error" )))
484
+ if ! reflect .DeepEqual (err , expectedErr ) {
485
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
486
+ }
487
+ },
488
+ },
489
+ {
490
+ name : "[Error] GetAuthEnv Error (could not find container name)" ,
491
+ testFunc : func (t * testing.T ) {
492
+ req := & csi.NodeStageVolumeRequest {
493
+ VolumeId : "unit-test" ,
494
+ StagingTargetPath : targetTest ,
495
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
496
+ VolumeContext : map [string ]string {
497
+ mountPermissionsField : "0755" ,
498
+ protocolField : "protocol" ,
499
+ },
500
+ Secrets : map [string ]string {},
501
+ }
502
+ d := NewFakeDriver ()
503
+ d .cloud = provider .GetTestCloud (gomock .NewController (t ))
504
+ d .cloud .ResourceGroup = "rg"
505
+ fakeMounter := & fakeMounter {}
506
+ fakeExec := & testingexec.FakeExec {}
507
+ d .mounter = & mount.SafeFormatAndMount {
508
+ Interface : fakeMounter ,
509
+ Exec : fakeExec ,
510
+ }
511
+ _ , err := d .NodeStageVolume (context .TODO (), req )
512
+ expectedErr := fmt .Errorf ("could not find containerName from attributes(%v) or volumeID(%v)" , req .GetVolumeContext (), req .VolumeId )
513
+ if ! reflect .DeepEqual (err , expectedErr ) {
514
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
515
+ }
516
+ },
517
+ },
518
+ {
519
+ name : "protocol = nfs" ,
520
+ testFunc : func (t * testing.T ) {
521
+ req := & csi.NodeStageVolumeRequest {
522
+ VolumeId : "rg#acc#cont#ns" ,
523
+ StagingTargetPath : targetTest ,
524
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
525
+ VolumeContext : map [string ]string {
526
+ mountPermissionsField : "0755" ,
527
+ protocolField : "nfs" ,
528
+ },
529
+ Secrets : map [string ]string {},
530
+ }
531
+ d := NewFakeDriver ()
532
+ d .cloud = provider .GetTestCloud (gomock .NewController (t ))
533
+ d .cloud .ResourceGroup = "rg"
534
+ d .enableBlobMockMount = true
535
+ fakeMounter := & fakeMounter {}
536
+ fakeExec := & testingexec.FakeExec {}
537
+ d .mounter = & mount.SafeFormatAndMount {
538
+ Interface : fakeMounter ,
539
+ Exec : fakeExec ,
540
+ }
541
+
542
+ _ , err := d .NodeStageVolume (context .TODO (), req )
543
+ //expectedErr := nil
544
+ if ! reflect .DeepEqual (err , nil ) {
545
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , nil )
546
+ }
547
+ },
548
+ },
549
+ {
550
+ name : "BlobMockMount Enabled" ,
551
+ testFunc : func (t * testing.T ) {
552
+ req := & csi.NodeStageVolumeRequest {
553
+ VolumeId : "rg#acc#cont#ns" ,
554
+ StagingTargetPath : targetTest ,
555
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
556
+ VolumeContext : map [string ]string {
557
+ mountPermissionsField : "0755" ,
558
+ protocolField : "protocol" ,
559
+ },
560
+ Secrets : map [string ]string {},
561
+ }
562
+ d := NewFakeDriver ()
563
+ d .cloud = provider .GetTestCloud (gomock .NewController (t ))
564
+ d .cloud .ResourceGroup = "rg"
565
+ d .enableBlobMockMount = true
566
+ fakeMounter := & fakeMounter {}
567
+ fakeExec := & testingexec.FakeExec {}
568
+ d .mounter = & mount.SafeFormatAndMount {
569
+ Interface : fakeMounter ,
570
+ Exec : fakeExec ,
571
+ }
572
+
573
+ keyList := make ([]storage.AccountKey , 1 )
574
+ fakeKey := "fakeKey"
575
+ fakeValue := "fakeValue"
576
+ keyList [0 ] = (storage.AccountKey {
577
+ KeyName : & fakeKey ,
578
+ Value : & fakeValue ,
579
+ })
580
+ d .cloud .StorageAccountClient = NewMockSAClient (gomock .NewController (t ), context .Background (), "subID" , "unit-test" , "unit-test" , & keyList )
581
+
582
+ _ , err := d .NodeStageVolume (context .TODO (), req )
583
+ //expectedErr := nil
584
+ if ! reflect .DeepEqual (err , nil ) {
585
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , nil )
586
+ }
587
+ },
588
+ },
459
589
}
460
590
for _ , tc := range testCases {
461
591
t .Run (tc .name , tc .testFunc )
@@ -520,6 +650,12 @@ func TestNodeUnstageVolume(t *testing.T) {
520
650
StagingTargetPath : "./unit-test" ,
521
651
}
522
652
d := NewFakeDriver ()
653
+ fakeMounter := & fakeMounter {}
654
+ fakeExec := & testingexec.FakeExec {}
655
+ d .mounter = & mount.SafeFormatAndMount {
656
+ Interface : fakeMounter ,
657
+ Exec : fakeExec ,
658
+ }
523
659
_ , err := d .NodeUnstageVolume (context .TODO (), req )
524
660
expectedErr := error (nil )
525
661
if ! reflect .DeepEqual (err , expectedErr ) {
0 commit comments