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>
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"io/ioutil" |
| 7 | 7 |
"os" |
| 8 | 8 |
"os/exec" |
| 9 |
+ "path" |
|
| 9 | 10 |
"path/filepath" |
| 10 | 11 |
"testing" |
| 11 | 12 |
) |
| ... | ... |
@@ -57,7 +58,7 @@ func TestCpGarbagePath(t *testing.T) {
|
| 57 | 57 |
tmpname := filepath.Join(tmpdir, cpTestName) |
| 58 | 58 |
defer os.RemoveAll(tmpdir) |
| 59 | 59 |
|
| 60 |
- path := filepath.Join("../../../../../../../../../../../../", cpFullPath)
|
|
| 60 |
+ path := path.Join("../../../../../../../../../../../../", cpFullPath)
|
|
| 61 | 61 |
|
| 62 | 62 |
_, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) |
| 63 | 63 |
if err != nil {
|
| ... | ... |
@@ -120,11 +121,18 @@ func TestCpRelativePath(t *testing.T) {
|
| 120 | 120 |
tmpname := filepath.Join(tmpdir, cpTestName) |
| 121 | 121 |
defer os.RemoveAll(tmpdir) |
| 122 | 122 |
|
| 123 |
- path, _ := filepath.Rel("/", cpFullPath)
|
|
| 123 |
+ var relPath string |
|
| 124 |
+ if path.IsAbs(cpFullPath) {
|
|
| 125 |
+ // normally this is `filepath.Rel("/", cpFullPath)` but we cannot
|
|
| 126 |
+ // get this unix-path manipulation on windows with filepath. |
|
| 127 |
+ relPath = cpFullPath[1:] |
|
| 128 |
+ } else {
|
|
| 129 |
+ t.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
|
|
| 130 |
+ } |
|
| 124 | 131 |
|
| 125 |
- _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) |
|
| 132 |
+ _, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+relPath, tmpdir) |
|
| 126 | 133 |
if err != nil {
|
| 127 |
- t.Fatalf("couldn't copy from relative path: %s:%s %s", cleanedContainerID, path, err)
|
|
| 134 |
+ t.Fatalf("couldn't copy from relative path: %s:%s %s", cleanedContainerID, relPath, err)
|
|
| 128 | 135 |
} |
| 129 | 136 |
|
| 130 | 137 |
file, _ := os.Open(tmpname) |
| ... | ... |
@@ -247,7 +255,7 @@ func TestCpAbsoluteSymlink(t *testing.T) {
|
| 247 | 247 |
tmpname := filepath.Join(tmpdir, cpTestName) |
| 248 | 248 |
defer os.RemoveAll(tmpdir) |
| 249 | 249 |
|
| 250 |
- path := filepath.Join("/", "container_path")
|
|
| 250 |
+ path := path.Join("/", "container_path")
|
|
| 251 | 251 |
|
| 252 | 252 |
_, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) |
| 253 | 253 |
if err != nil {
|
| ... | ... |
@@ -311,7 +319,7 @@ func TestCpSymlinkComponent(t *testing.T) {
|
| 311 | 311 |
tmpname := filepath.Join(tmpdir, cpTestName) |
| 312 | 312 |
defer os.RemoveAll(tmpdir) |
| 313 | 313 |
|
| 314 |
- path := filepath.Join("/", "container_path", cpTestName)
|
|
| 314 |
+ path := path.Join("/", "container_path", cpTestName)
|
|
| 315 | 315 |
|
| 316 | 316 |
_, _, err = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir) |
| 317 | 317 |
if err != nil {
|