integration-cli: use cmd.Stdin instead of cat/tee for TestExportContainerAndImportImage
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>
This commit is contained in:
parent
aa073ac05e
commit
48d8757700
1 changed files with 4 additions and 9 deletions
|
@ -1,9 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,15 +22,13 @@ func TestExportContainerAndImportImage(t *testing.T) {
|
||||||
t.Fatalf("output should've been a container id: %s %s ", cleanedContainerID, err)
|
t.Fatalf("output should've been a container id: %s %s ", cleanedContainerID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
exportCmdTemplate := `%v export %v > /tmp/testexp.tar`
|
exportCmd := exec.Command(dockerBinary, "export", cleanedContainerID)
|
||||||
exportCmdFinal := fmt.Sprintf(exportCmdTemplate, dockerBinary, cleanedContainerID)
|
|
||||||
exportCmd := exec.Command("bash", "-c", exportCmdFinal)
|
|
||||||
if out, _, err = runCommandWithOutput(exportCmd); err != nil {
|
if out, _, err = runCommandWithOutput(exportCmd); err != nil {
|
||||||
t.Fatalf("failed to export container: %s, %v", out, err)
|
t.Fatalf("failed to export container: %s, %v", out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
importCmdFinal := `cat /tmp/testexp.tar | docker import - repo/testexp:v1`
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
||||||
importCmd := exec.Command("bash", "-c", importCmdFinal)
|
importCmd.Stdin = strings.NewReader(out)
|
||||||
out, _, err = runCommandWithOutput(importCmd)
|
out, _, err = runCommandWithOutput(importCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to import image: %s, %v", out, err)
|
t.Fatalf("failed to import image: %s, %v", out, err)
|
||||||
|
@ -47,8 +44,6 @@ func TestExportContainerAndImportImage(t *testing.T) {
|
||||||
deleteContainer(cleanedContainerID)
|
deleteContainer(cleanedContainerID)
|
||||||
deleteImages("repo/testexp:v1")
|
deleteImages("repo/testexp:v1")
|
||||||
|
|
||||||
os.Remove("/tmp/testexp.tar")
|
|
||||||
|
|
||||||
logDone("export - export a container")
|
logDone("export - export a container")
|
||||||
logDone("import - import an image")
|
logDone("import - import an image")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue