未验证 提交 29f0aec4 编写于 作者: M Medya Ghazizadeh 提交者: GitHub

Merge pull request #10920 from anencore94/cp_window

Fix to minikube cp functional test work on windows os
......@@ -22,7 +22,7 @@ import (
"os"
pt "path"
"path/filepath"
"strings"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/exit"
......@@ -87,7 +87,7 @@ func validateArgs(srcPath string, dstPath string) {
}
}
if !filepath.IsAbs(dstPath) {
if !strings.HasPrefix(dstPath, "/") {
exit.Message(reason.Usage, `<target file absolute path> must be an absolute Path. Relative Path is not allowed (example: "/home/docker/copied.txt")`)
}
}
......@@ -1234,14 +1234,26 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
}
}
// cpTestMinikubePath is where the test file will be located in the Minikube instance
func cpTestMinikubePath() string {
return "/home/docker/cp-test.txt"
}
// cpTestLocalPath is where the test file located in host os
func cpTestLocalPath() string {
return filepath.Join(*testdataDir, "cp-test.txt")
}
// validateCpCmd asserts basic "cp" command functionality
func validateCpCmd(ctx context.Context, t *testing.T, profile string) {
if NoneDriver() {
t.Skipf("skipping: cp is unsupported by none driver")
}
cpPath := filepath.Join(*testdataDir, "cp-test.txt")
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cp", cpPath, "/home/docker/hello_cp.txt"))
srcPath := cpTestLocalPath()
dstPath := cpTestMinikubePath()
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cp", srcPath, dstPath))
if ctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
}
......@@ -1249,15 +1261,20 @@ func validateCpCmd(ctx context.Context, t *testing.T, profile string) {
t.Errorf("failed to run an cp command. args %q : %v", rr.Command(), err)
}
expected := "Test file for checking file cp process"
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat /home/docker/hello_cp.txt"))
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("sudo cat %s", dstPath)))
if ctx.Err() == context.DeadlineExceeded {
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
}
if err != nil {
t.Errorf("failed to run an cp command. args %q : %v", rr.Command(), err)
}
if diff := cmp.Diff(expected, rr.Stdout.String()); diff != "" {
expected, err := ioutil.ReadFile(srcPath)
if err != nil {
t.Errorf("failed to read test file 'testdata/cp-test.txt' : %v", err)
}
if diff := cmp.Diff(string(expected), rr.Stdout.String()); diff != "" {
t.Errorf("/testdata/cp-test.txt content mismatch (-want +got):\n%s", diff)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册