From c5b312dcf5efa4f91dee59f4b701ea7a26a6d41e Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 18 Feb 2015 01:55:08 -0800 Subject: [PATCH] integ-cli: Fix path issues in docker cp tests Some of the `docker cp` tests were using `path/filepath` to craft unix paths. This wouldn't work on Windows since filepath is platform-dependent. Moved code to `path` as much as possible and hacked away some `path/filepath` functionality that doesn't exist in `path` pkg. This fixes the following test cases: - `TestCpGarbagePath` - `TestCpRelativePath` - `TestCpAbsoluteSymlink` - `TestCpSymlinkComponent` Signed-off-by: Ahmet Alp Balkan --- integration-cli/docker_cli_cp_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/integration-cli/docker_cli_cp_test.go b/integration-cli/docker_cli_cp_test.go index 7002e1a34a..070b890257 100644 --- a/integration-cli/docker_cli_cp_test.go +++ b/integration-cli/docker_cli_cp_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "os/exec" + "path" "path/filepath" "testing" ) @@ -57,7 +58,7 @@ func TestCpGarbagePath(t *testing.T) { tmpname := filepath.Join(tmpdir, cpTestName) defer os.RemoveAll(tmpdir) - path := filepath.Join("../../../../../../../../../../../../", cpFullPath) + path := path.Join("../../../../../../../../../../../../", cpFullPath) _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) if err != nil { @@ -120,11 +121,18 @@ func TestCpRelativePath(t *testing.T) { tmpname := filepath.Join(tmpdir, cpTestName) defer os.RemoveAll(tmpdir) - path, _ := filepath.Rel("/", cpFullPath) + var relPath string + if path.IsAbs(cpFullPath) { + // normally this is `filepath.Rel("/", cpFullPath)` but we cannot + // get this unix-path manipulation on windows with filepath. + relPath = cpFullPath[1:] + } else { + t.Fatalf("path %s was assumed to be an absolute path", cpFullPath) + } - _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) + _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+relPath, tmpdir) if err != nil { - t.Fatalf("couldn't copy from relative path: %s:%s %s", cleanedContainerID, path, err) + t.Fatalf("couldn't copy from relative path: %s:%s %s", cleanedContainerID, relPath, err) } file, _ := os.Open(tmpname) @@ -247,7 +255,7 @@ func TestCpAbsoluteSymlink(t *testing.T) { tmpname := filepath.Join(tmpdir, cpTestName) defer os.RemoveAll(tmpdir) - path := filepath.Join("/", "container_path") + path := path.Join("/", "container_path") _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) if err != nil { @@ -311,7 +319,7 @@ func TestCpSymlinkComponent(t *testing.T) { tmpname := filepath.Join(tmpdir, cpTestName) defer os.RemoveAll(tmpdir) - path := filepath.Join("/", "container_path", cpTestName) + path := path.Join("/", "container_path", cpTestName) _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) if err != nil {