os.Exec("bash", "-c", dockerBinary) ends up making a call like
bash -c c:\...\docker.exe on windows msys shell, which does not work.
This test makes use of exec.Command.Stdin to pass image back to
docker import.
- Upside: fixes the test on windows
- Downside: cat/tee compatibility is no longer tested in this test case
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
... | ... |
@@ -1,9 +1,8 @@ |
1 | 1 |
package main |
2 | 2 |
|
3 | 3 |
import ( |
4 |
- "fmt" |
|
5 |
- "os" |
|
6 | 4 |
"os/exec" |
5 |
+ "strings" |
|
7 | 6 |
"testing" |
8 | 7 |
) |
9 | 8 |
|
... | ... |
@@ -23,15 +22,13 @@ func TestExportContainerAndImportImage(t *testing.T) { |
23 | 23 |
t.Fatalf("output should've been a container id: %s %s ", cleanedContainerID, err) |
24 | 24 |
} |
25 | 25 |
|
26 |
- exportCmdTemplate := `%v export %v > /tmp/testexp.tar` |
|
27 |
- exportCmdFinal := fmt.Sprintf(exportCmdTemplate, dockerBinary, cleanedContainerID) |
|
28 |
- exportCmd := exec.Command("bash", "-c", exportCmdFinal) |
|
26 |
+ exportCmd := exec.Command(dockerBinary, "export", cleanedContainerID) |
|
29 | 27 |
if out, _, err = runCommandWithOutput(exportCmd); err != nil { |
30 | 28 |
t.Fatalf("failed to export container: %s, %v", out, err) |
31 | 29 |
} |
32 | 30 |
|
33 |
- importCmdFinal := `cat /tmp/testexp.tar | docker import - repo/testexp:v1` |
|
34 |
- importCmd := exec.Command("bash", "-c", importCmdFinal) |
|
31 |
+ importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") |
|
32 |
+ importCmd.Stdin = strings.NewReader(out) |
|
35 | 33 |
out, _, err = runCommandWithOutput(importCmd) |
36 | 34 |
if err != nil { |
37 | 35 |
t.Fatalf("failed to import image: %s, %v", out, err) |
... | ... |
@@ -47,8 +44,6 @@ func TestExportContainerAndImportImage(t *testing.T) { |
47 | 47 |
deleteContainer(cleanedContainerID) |
48 | 48 |
deleteImages("repo/testexp:v1") |
49 | 49 |
|
50 |
- os.Remove("/tmp/testexp.tar") |
|
51 |
- |
|
52 | 50 |
logDone("export - export a container") |
53 | 51 |
logDone("import - import an image") |
54 | 52 |
} |