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 <ahmetalpbalkan@gmail.com>
This commit is contained in:
parent
2f024bd9e1
commit
c5b312dcf5
1 changed files with 14 additions and 6 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue