2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-12-19 05:25:33 -05:00
|
|
|
"os"
|
2014-02-25 11:17:48 -05:00
|
|
|
"os/exec"
|
2015-02-14 01:01:58 -05:00
|
|
|
"strings"
|
2014-02-25 11:17:48 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// export an image and try to import it into a new one
|
|
|
|
func TestExportContainerAndImportImage(t *testing.T) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("failed to create a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanedContainerID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
|
|
|
out, _, err = runCommandWithOutput(inspectCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("output should've been a container id: %s %s ", cleanedContainerID, err)
|
|
|
|
}
|
|
|
|
|
2015-02-14 01:01:58 -05:00
|
|
|
exportCmd := exec.Command(dockerBinary, "export", cleanedContainerID)
|
2014-10-14 15:25:46 -04:00
|
|
|
if out, _, err = runCommandWithOutput(exportCmd); err != nil {
|
|
|
|
t.Fatalf("failed to export container: %s, %v", out, err)
|
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-02-14 01:01:58 -05:00
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
|
|
|
importCmd.Stdin = strings.NewReader(out)
|
2014-02-25 11:17:48 -05:00
|
|
|
out, _, err = runCommandWithOutput(importCmd)
|
2014-10-14 15:25:46 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to import image: %s, %v", out, err)
|
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
cleanedImageID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd = exec.Command(dockerBinary, "inspect", cleanedImageID)
|
2014-10-14 15:25:46 -04:00
|
|
|
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
|
|
|
t.Fatalf("output should've been an image id: %s, %v", out, err)
|
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2014-04-03 20:22:32 -04:00
|
|
|
deleteContainer(cleanedContainerID)
|
2014-08-26 03:03:38 -04:00
|
|
|
deleteImages("repo/testexp:v1")
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-03-26 20:25:50 -04:00
|
|
|
logDone("export - export/import a container/image")
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2014-12-19 05:25:33 -05:00
|
|
|
|
|
|
|
// Used to test output flag in the export command
|
|
|
|
func TestExportContainerWithOutputAndImportImage(t *testing.T) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("failed to create a container", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanedContainerID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
|
|
|
out, _, err = runCommandWithOutput(inspectCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("output should've been a container id: %s %s ", cleanedContainerID, err)
|
|
|
|
}
|
|
|
|
|
2015-03-17 03:36:56 -04:00
|
|
|
exportCmd := exec.Command(dockerBinary, "export", "--output=testexp.tar", cleanedContainerID)
|
2014-12-19 05:25:33 -05:00
|
|
|
if out, _, err = runCommandWithOutput(exportCmd); err != nil {
|
|
|
|
t.Fatalf("failed to export container: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
|
2015-03-17 03:36:56 -04:00
|
|
|
out, _, err = runCommandWithOutput(exec.Command("cat", "testexp.tar"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
|
|
|
importCmd.Stdin = strings.NewReader(out)
|
2014-12-19 05:25:33 -05:00
|
|
|
out, _, err = runCommandWithOutput(importCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to import image: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanedImageID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd = exec.Command(dockerBinary, "inspect", cleanedImageID)
|
|
|
|
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
|
|
|
t.Fatalf("output should've been an image id: %s, %v", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteContainer(cleanedContainerID)
|
|
|
|
deleteImages("repo/testexp:v1")
|
|
|
|
|
|
|
|
os.Remove("/tmp/testexp.tar")
|
|
|
|
|
2015-03-26 20:25:50 -04:00
|
|
|
logDone("export - export/import a container/image with output flag")
|
2014-12-19 05:25:33 -05:00
|
|
|
}
|