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