@@ -17,7 +17,10 @@ package gceGCEDriver
17
17
18
18
import (
19
19
"context"
20
+ "fmt"
20
21
"io/ioutil"
22
+ "k8s.io/utils/exec"
23
+ testingexec "k8s.io/utils/exec/testing"
21
24
"os"
22
25
"path/filepath"
23
26
"testing"
@@ -63,6 +66,15 @@ func getTestBlockingGCEDriver(t *testing.T, readyToExecute chan chan struct{}) *
63
66
return gceDriver
64
67
}
65
68
69
+ func makeFakeCmd (fakeCmd * testingexec.FakeCmd , cmd string , args ... string ) testingexec.FakeCommandAction {
70
+ c := cmd
71
+ a := args
72
+ return func (cmd string , args ... string ) exec.Cmd {
73
+ command := testingexec .InitFakeCmd (fakeCmd , c , a ... )
74
+ return command
75
+ }
76
+ }
77
+
66
78
func TestNodeGetVolumeStats (t * testing.T ) {
67
79
gceDriver := getTestGCEDriver (t )
68
80
ns := gceDriver .ns
@@ -351,8 +363,6 @@ func TestNodeUnpublishVolume(t *testing.T) {
351
363
}
352
364
353
365
func TestNodeStageVolume (t * testing.T ) {
354
- gceDriver := getTestGCEDriver (t )
355
- ns := gceDriver .ns
356
366
volumeID := "project/test001/zones/c1/disks/testDisk"
357
367
blockCap := & csi.VolumeCapability_Block {
358
368
Block : & csi.VolumeCapability_BlockVolume {},
@@ -436,6 +446,61 @@ func TestNodeStageVolume(t *testing.T) {
436
446
}
437
447
for _ , tc := range testCases {
438
448
t .Logf ("Test case: %s" , tc .name )
449
+ actionList := []testingexec.FakeCommandAction {
450
+ makeFakeCmd (
451
+ & testingexec.FakeCmd {
452
+ CombinedOutputScript : []testingexec.FakeAction {
453
+ func () ([]byte , []byte , error ) {
454
+ return []byte (fmt .Sprintf ("DEVNAME=/dev/sdb\n TYPE=ext4" )), nil , nil
455
+ },
456
+ },
457
+ },
458
+ "blkid" ,
459
+ ),
460
+ makeFakeCmd (
461
+ & testingexec.FakeCmd {
462
+ CombinedOutputScript : []testingexec.FakeAction {
463
+ func () ([]byte , []byte , error ) {
464
+ return []byte ("1" ), nil , nil
465
+ },
466
+ },
467
+ },
468
+ "blockdev" ,
469
+ ),
470
+ makeFakeCmd (
471
+ & testingexec.FakeCmd {
472
+ CombinedOutputScript : []testingexec.FakeAction {
473
+ func () ([]byte , []byte , error ) {
474
+ return []byte ("1" ), nil , nil
475
+ },
476
+ },
477
+ },
478
+ "blockdev" ,
479
+ ),
480
+ makeFakeCmd (
481
+ & testingexec.FakeCmd {
482
+ CombinedOutputScript : []testingexec.FakeAction {
483
+ func () ([]byte , []byte , error ) {
484
+ return []byte (fmt .Sprintf ("DEVNAME=/dev/sdb\n TYPE=ext4" )), nil , nil
485
+ },
486
+ },
487
+ },
488
+ "blkid" ,
489
+ ),
490
+ makeFakeCmd (
491
+ & testingexec.FakeCmd {
492
+ CombinedOutputScript : []testingexec.FakeAction {
493
+ func () ([]byte , []byte , error ) {
494
+ return []byte (fmt .Sprintf ("block size: 1\n block count: 1" )), nil , nil
495
+ },
496
+ },
497
+ },
498
+ "dumpe2fs" ,
499
+ ),
500
+ }
501
+ mounter := mountmanager .NewFakeSafeMounterWithCustomExec (& testingexec.FakeExec {CommandScript : actionList })
502
+ gceDriver := getTestGCEDriverWithCustomMounter (t , mounter )
503
+ ns := gceDriver .ns
439
504
_ , err := ns .NodeStageVolume (context .Background (), tc .req )
440
505
if err != nil {
441
506
serverError , ok := status .FromError (err )
0 commit comments