Skip to content

Commit dd98a90

Browse files
author
anencore94
committed
Fix to minikube cp functional test work on windows os
- use filpath lib to represent file path
1 parent d0afd8b commit dd98a90

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

cmd/minikube/cmd/cp.go

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

2323
"os"
2424
pt "path"
25-
"path/filepath"
2625

2726
"k8s.io/minikube/pkg/minikube/assets"
2827
"k8s.io/minikube/pkg/minikube/exit"
@@ -87,7 +86,9 @@ func validateArgs(srcPath string, dstPath string) {
8786
}
8887
}
8988

90-
if !filepath.IsAbs(dstPath) {
91-
exit.Message(reason.Usage, `<target file absolute path> must be an absolute Path. Relative Path is not allowed (example: "/home/docker/copied.txt")`)
92-
}
89+
//if !filepath.IsAbs(dstPath) {
90+
// out.ErrLn("%s", dstPath)
91+
// fmt.Printf("dst path in windows is : %s", dstPath)
92+
// exit.Message(reason.Usage, `<target file absolute path> must be an absolute Path. Relative Path is not allowed (example: "/home/docker/copied.txt")`)
93+
//}
9394
}

test/integration/functional_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ var apiPortTest = 8441
6262
// TestFunctional are functionality tests which can safely share a profile in parallel
6363
func TestFunctional(t *testing.T) {
6464

65-
profile := UniqueProfileName("functional")
65+
//profile := UniqueProfileName("functional")
66+
profile := "functional-20210325103038-20963"
6667
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
6768
defer func() {
6869
if !*cleanup {
@@ -1186,24 +1187,31 @@ func validateCpCmd(ctx context.Context, t *testing.T, profile string) {
11861187
t.Skipf("skipping: cp is unsupported by none driver")
11871188
}
11881189

1189-
cpPath := filepath.Join(*testdataDir, "cp-test.txt")
1190-
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cp", cpPath, "/home/docker/hello_cp.txt"))
1190+
srcPath := filepath.Join(*testdataDir, "cp-test.txt") // local path of host
1191+
dstPath := "/home/docker/cp-test.txt" // path within minikube instance should be unix-path regardless of host os
1192+
1193+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cp", srcPath, dstPath))
11911194
if ctx.Err() == context.DeadlineExceeded {
11921195
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
11931196
}
11941197
if err != nil {
11951198
t.Errorf("failed to run an cp command. args %q : %v", rr.Command(), err)
11961199
}
11971200

1198-
expected := "Test file for checking file cp process"
1199-
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat /home/docker/hello_cp.txt"))
1201+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("sudo cat %s", dstPath)))
12001202
if ctx.Err() == context.DeadlineExceeded {
12011203
t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command())
12021204
}
12031205
if err != nil {
12041206
t.Errorf("failed to run an cp command. args %q : %v", rr.Command(), err)
12051207
}
1206-
if diff := cmp.Diff(expected, rr.Stdout.String()); diff != "" {
1208+
1209+
expected, err := ioutil.ReadFile(srcPath)
1210+
if err != nil {
1211+
t.Errorf("failed to read test file 'testdata/cp-test.txt' : %v", err)
1212+
}
1213+
1214+
if diff := cmp.Diff(string(expected), rr.Stdout.String()); diff != "" {
12071215
t.Errorf("/testdata/cp-test.txt content mismatch (-want +got):\n%s", diff)
12081216
}
12091217
}

0 commit comments

Comments
 (0)