@@ -1234,30 +1234,47 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
12341234 }
12351235}
12361236
1237+ // cpTestMinikubePath is where the test file will be located in the Minikube instance
1238+ func cpTestMinikubePath () string {
1239+ return "/home/docker/cp-test.txt"
1240+ }
1241+
1242+ // cpTestLocalPath is where the test file located in host os
1243+ func cpTestLocalPath () string {
1244+ return filepath .Join (* testdataDir , "cp-test.txt" )
1245+ }
1246+
12371247// validateCpCmd asserts basic "cp" command functionality
12381248func validateCpCmd (ctx context.Context , t * testing.T , profile string ) {
12391249 if NoneDriver () {
12401250 t .Skipf ("skipping: cp is unsupported by none driver" )
12411251 }
12421252
1243- cpPath := filepath .Join (* testdataDir , "cp-test.txt" )
1244- rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "cp" , cpPath , "/home/docker/hello_cp.txt" ))
1253+ srcPath := cpTestLocalPath ()
1254+ dstPath := cpTestMinikubePath ()
1255+
1256+ rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "cp" , srcPath , dstPath ))
12451257 if ctx .Err () == context .DeadlineExceeded {
12461258 t .Errorf ("failed to run command by deadline. exceeded timeout : %s" , rr .Command ())
12471259 }
12481260 if err != nil {
12491261 t .Errorf ("failed to run an cp command. args %q : %v" , rr .Command (), err )
12501262 }
12511263
1252- expected := "Test file for checking file cp process"
1253- rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "ssh" , "cat /home/docker/hello_cp.txt" ))
1264+ rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "ssh" , fmt .Sprintf ("sudo cat %s" , dstPath )))
12541265 if ctx .Err () == context .DeadlineExceeded {
12551266 t .Errorf ("failed to run command by deadline. exceeded timeout : %s" , rr .Command ())
12561267 }
12571268 if err != nil {
12581269 t .Errorf ("failed to run an cp command. args %q : %v" , rr .Command (), err )
12591270 }
1260- if diff := cmp .Diff (expected , rr .Stdout .String ()); diff != "" {
1271+
1272+ expected , err := ioutil .ReadFile (srcPath )
1273+ if err != nil {
1274+ t .Errorf ("failed to read test file 'testdata/cp-test.txt' : %v" , err )
1275+ }
1276+
1277+ if diff := cmp .Diff (string (expected ), rr .Stdout .String ()); diff != "" {
12611278 t .Errorf ("/testdata/cp-test.txt content mismatch (-want +got):\n %s" , diff )
12621279 }
12631280}
0 commit comments