Skip to content

Commit 29f0aec

Browse files
authored
Merge pull request #10920 from anencore94/cp_window
Fix to minikube cp functional test work on windows os
2 parents 3efdadb + 4f9aac3 commit 29f0aec

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cmd/minikube/cmd/cp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"os"
2424
pt "path"
25-
"path/filepath"
25+
"strings"
2626

2727
"k8s.io/minikube/pkg/minikube/assets"
2828
"k8s.io/minikube/pkg/minikube/exit"
@@ -87,7 +87,7 @@ func validateArgs(srcPath string, dstPath string) {
8787
}
8888
}
8989

90-
if !filepath.IsAbs(dstPath) {
90+
if !strings.HasPrefix(dstPath, "/") {
9191
exit.Message(reason.Usage, `<target file absolute path> must be an absolute Path. Relative Path is not allowed (example: "/home/docker/copied.txt")`)
9292
}
9393
}

test/integration/functional_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
12381248
func 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

Comments
 (0)