mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Cleanup errorOut resp in save tests
Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
parent
0e3744ec89
commit
0c87424007
1 changed files with 78 additions and 46 deletions
|
@ -14,40 +14,50 @@ import (
|
||||||
func TestSaveAndLoadRepoStdout(t *testing.T) {
|
func TestSaveAndLoadRepoStdout(t *testing.T) {
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("failed to create a container: %v %v", out, err))
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create a container: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
cleanedContainerID := stripTrailingCharacters(out)
|
cleanedContainerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
repoName := "foobar-save-load-test"
|
repoName := "foobar-save-load-test"
|
||||||
|
|
||||||
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
||||||
out, _, err = runCommandWithOutput(inspectCmd)
|
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("output should've been a container id: %v %v", cleanedContainerID, err))
|
t.Fatalf("output should've been a container id: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
|
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
|
||||||
out, _, err = runCommandWithOutput(commitCmd)
|
if out, _, err = runCommandWithOutput(commitCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to commit container: %v %v", out, err))
|
t.Fatalf("failed to commit container: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
before, _, err := runCommandWithOutput(inspectCmd)
|
before, _, err := runCommandWithOutput(inspectCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("the repo should exist before saving it: %v %v", before, err))
|
if err != nil {
|
||||||
|
t.Fatalf("the repo should exist before saving it: %s, %v", before, err)
|
||||||
|
}
|
||||||
|
|
||||||
saveCmdTemplate := `%v save %v > /tmp/foobar-save-load-test.tar`
|
saveCmdTemplate := `%v save %v > /tmp/foobar-save-load-test.tar`
|
||||||
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName)
|
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName)
|
||||||
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(saveCmd)
|
if out, _, err = runCommandWithOutput(saveCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to save repo: %v %v", out, err))
|
t.Fatalf("failed to save repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
deleteImages(repoName)
|
deleteImages(repoName)
|
||||||
|
|
||||||
loadCmdFinal := `cat /tmp/foobar-save-load-test.tar | docker load`
|
loadCmdFinal := `cat /tmp/foobar-save-load-test.tar | docker load`
|
||||||
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
|
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(loadCmd)
|
if out, _, err = runCommandWithOutput(loadCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to load repo: %v %v", out, err))
|
t.Fatalf("failed to load repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
after, _, err := runCommandWithOutput(inspectCmd)
|
after, _, err := runCommandWithOutput(inspectCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("the repo should exist after loading it: %v %v", after, err))
|
if err != nil {
|
||||||
|
t.Fatalf("the repo should exist after loading it: %s %v", after, err)
|
||||||
|
}
|
||||||
|
|
||||||
if before != after {
|
if before != after {
|
||||||
t.Fatalf("inspect is not the same after a save / load")
|
t.Fatalf("inspect is not the same after a save / load")
|
||||||
|
@ -67,20 +77,24 @@ func TestSaveSingleTag(t *testing.T) {
|
||||||
|
|
||||||
tagCmdFinal := fmt.Sprintf("%v tag busybox:latest %v:latest", dockerBinary, repoName)
|
tagCmdFinal := fmt.Sprintf("%v tag busybox:latest %v:latest", dockerBinary, repoName)
|
||||||
tagCmd := exec.Command("bash", "-c", tagCmdFinal)
|
tagCmd := exec.Command("bash", "-c", tagCmdFinal)
|
||||||
out, _, err := runCommandWithOutput(tagCmd)
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to tag repo: %v %v", out, err))
|
t.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
idCmdFinal := fmt.Sprintf("%v images -q --no-trunc %v", dockerBinary, repoName)
|
idCmdFinal := fmt.Sprintf("%v images -q --no-trunc %v", dockerBinary, repoName)
|
||||||
idCmd := exec.Command("bash", "-c", idCmdFinal)
|
idCmd := exec.Command("bash", "-c", idCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(idCmd)
|
out, _, err := runCommandWithOutput(idCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("failed to get repo ID: %v %v", out, err))
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get repo ID: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
cleanedImageID := stripTrailingCharacters(out)
|
cleanedImageID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
saveCmdFinal := fmt.Sprintf("%v save %v:latest | tar t | grep -E '(^repositories$|%v)'", dockerBinary, repoName, cleanedImageID)
|
saveCmdFinal := fmt.Sprintf("%v save %v:latest | tar t | grep -E '(^repositories$|%v)'", dockerBinary, repoName, cleanedImageID)
|
||||||
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(saveCmd)
|
if out, _, err = runCommandWithOutput(saveCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to save repo with image ID and 'repositories' file: %v %v", out, err))
|
t.Fatalf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
deleteImages(repoName)
|
deleteImages(repoName)
|
||||||
|
|
||||||
|
@ -92,27 +106,33 @@ func TestSaveImageId(t *testing.T) {
|
||||||
|
|
||||||
tagCmdFinal := fmt.Sprintf("%v tag scratch:latest %v:latest", dockerBinary, repoName)
|
tagCmdFinal := fmt.Sprintf("%v tag scratch:latest %v:latest", dockerBinary, repoName)
|
||||||
tagCmd := exec.Command("bash", "-c", tagCmdFinal)
|
tagCmd := exec.Command("bash", "-c", tagCmdFinal)
|
||||||
out, _, err := runCommandWithOutput(tagCmd)
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to tag repo: %v %v", out, err))
|
t.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
idLongCmdFinal := fmt.Sprintf("%v images -q --no-trunc %v", dockerBinary, repoName)
|
idLongCmdFinal := fmt.Sprintf("%v images -q --no-trunc %v", dockerBinary, repoName)
|
||||||
idLongCmd := exec.Command("bash", "-c", idLongCmdFinal)
|
idLongCmd := exec.Command("bash", "-c", idLongCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(idLongCmd)
|
out, _, err := runCommandWithOutput(idLongCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("failed to get repo ID: %v %v", out, err))
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get repo ID: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
cleanedLongImageID := stripTrailingCharacters(out)
|
cleanedLongImageID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
idShortCmdFinal := fmt.Sprintf("%v images -q %v", dockerBinary, repoName)
|
idShortCmdFinal := fmt.Sprintf("%v images -q %v", dockerBinary, repoName)
|
||||||
idShortCmd := exec.Command("bash", "-c", idShortCmdFinal)
|
idShortCmd := exec.Command("bash", "-c", idShortCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(idShortCmd)
|
out, _, err = runCommandWithOutput(idShortCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("failed to get repo short ID: %v %v", out, err))
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get repo short ID: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
cleanedShortImageID := stripTrailingCharacters(out)
|
cleanedShortImageID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
saveCmdFinal := fmt.Sprintf("%v save %v | tar t | grep %v", dockerBinary, cleanedShortImageID, cleanedLongImageID)
|
saveCmdFinal := fmt.Sprintf("%v save %v | tar t | grep %v", dockerBinary, cleanedShortImageID, cleanedLongImageID)
|
||||||
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(saveCmd)
|
if out, _, err = runCommandWithOutput(saveCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to save repo with image ID: %v %v", out, err))
|
t.Fatalf("failed to save repo with image ID: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
deleteImages(repoName)
|
deleteImages(repoName)
|
||||||
|
|
||||||
|
@ -123,40 +143,50 @@ func TestSaveImageId(t *testing.T) {
|
||||||
func TestSaveAndLoadRepoFlags(t *testing.T) {
|
func TestSaveAndLoadRepoFlags(t *testing.T) {
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("failed to create a container: %v %v", out, err))
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create a container: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
cleanedContainerID := stripTrailingCharacters(out)
|
cleanedContainerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
repoName := "foobar-save-load-test"
|
repoName := "foobar-save-load-test"
|
||||||
|
|
||||||
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
|
||||||
out, _, err = runCommandWithOutput(inspectCmd)
|
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("output should've been a container id: %v %v", cleanedContainerID, err))
|
t.Fatalf("output should've been a container id: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
|
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
|
||||||
out, _, err = runCommandWithOutput(commitCmd)
|
if out, _, err = runCommandWithOutput(commitCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to commit container: %v %v", out, err))
|
t.Fatalf("failed to commit container: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
before, _, err := runCommandWithOutput(inspectCmd)
|
before, _, err := runCommandWithOutput(inspectCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("the repo should exist before saving it: %v %v", before, err))
|
if err != nil {
|
||||||
|
t.Fatalf("the repo should exist before saving it: %s, %v", before, err)
|
||||||
|
}
|
||||||
|
|
||||||
saveCmdTemplate := `%v save -o /tmp/foobar-save-load-test.tar %v`
|
saveCmdTemplate := `%v save -o /tmp/foobar-save-load-test.tar %v`
|
||||||
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName)
|
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName)
|
||||||
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(saveCmd)
|
if out, _, err = runCommandWithOutput(saveCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to save repo: %v %v", out, err))
|
t.Fatalf("failed to save repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
deleteImages(repoName)
|
deleteImages(repoName)
|
||||||
|
|
||||||
loadCmdFinal := `docker load -i /tmp/foobar-save-load-test.tar`
|
loadCmdFinal := `docker load -i /tmp/foobar-save-load-test.tar`
|
||||||
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
|
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(loadCmd)
|
if out, _, err = runCommandWithOutput(loadCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to load repo: %v %v", out, err))
|
t.Fatalf("failed to load repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
||||||
after, _, err := runCommandWithOutput(inspectCmd)
|
after, _, err := runCommandWithOutput(inspectCmd)
|
||||||
errorOut(err, t, fmt.Sprintf("the repo should exist after loading it: %v %v", after, err))
|
if err != nil {
|
||||||
|
t.Fatalf("the repo should exist after loading it: %s, %v", after, err)
|
||||||
|
}
|
||||||
|
|
||||||
if before != after {
|
if before != after {
|
||||||
t.Fatalf("inspect is not the same after a save / load")
|
t.Fatalf("inspect is not the same after a save / load")
|
||||||
|
@ -177,18 +207,21 @@ func TestSaveMultipleNames(t *testing.T) {
|
||||||
// Make one image
|
// Make one image
|
||||||
tagCmdFinal := fmt.Sprintf("%v tag scratch:latest %v-one:latest", dockerBinary, repoName)
|
tagCmdFinal := fmt.Sprintf("%v tag scratch:latest %v-one:latest", dockerBinary, repoName)
|
||||||
tagCmd := exec.Command("bash", "-c", tagCmdFinal)
|
tagCmd := exec.Command("bash", "-c", tagCmdFinal)
|
||||||
out, _, err := runCommandWithOutput(tagCmd)
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to tag repo: %v %v", out, err))
|
t.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
// Make two images
|
// Make two images
|
||||||
tagCmdFinal = fmt.Sprintf("%v tag scratch:latest %v-two:latest", dockerBinary, repoName)
|
tagCmdFinal = fmt.Sprintf("%v tag scratch:latest %v-two:latest", dockerBinary, repoName)
|
||||||
tagCmd = exec.Command("bash", "-c", tagCmdFinal)
|
tagCmd = exec.Command("bash", "-c", tagCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(tagCmd)
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to tag repo: %v %v", out, err))
|
t.Fatalf("failed to tag repo: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
saveCmdFinal := fmt.Sprintf("%v save %v-one %v-two:latest | tar xO repositories | grep -q -E '(-one|-two)'", dockerBinary, repoName, repoName)
|
saveCmdFinal := fmt.Sprintf("%v save %v-one %v-two:latest | tar xO repositories | grep -q -E '(-one|-two)'", dockerBinary, repoName, repoName)
|
||||||
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
out, _, err = runCommandWithOutput(saveCmd)
|
if out, _, err := runCommandWithOutput(saveCmd); err != nil {
|
||||||
errorOut(err, t, fmt.Sprintf("failed to save multiple repos: %v %v", out, err))
|
t.Fatalf("failed to save multiple repos: %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
deleteImages(repoName)
|
deleteImages(repoName)
|
||||||
|
|
||||||
|
@ -202,12 +235,12 @@ func TestSaveDirectoryPermissions(t *testing.T) {
|
||||||
|
|
||||||
name := "save-directory-permissions"
|
name := "save-directory-permissions"
|
||||||
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
|
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
|
||||||
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
|
|
||||||
os.Mkdir(extractionDirectory, 0777)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create temporary directory: %s", err)
|
t.Errorf("failed to create temporary directory: %s", err)
|
||||||
}
|
}
|
||||||
|
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
|
||||||
|
os.Mkdir(extractionDirectory, 0777)
|
||||||
|
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
defer deleteImages(name)
|
defer deleteImages(name)
|
||||||
_, err = buildImage(name,
|
_, err = buildImage(name,
|
||||||
|
@ -221,8 +254,7 @@ func TestSaveDirectoryPermissions(t *testing.T) {
|
||||||
|
|
||||||
saveCmdFinal := fmt.Sprintf("%s save %s | tar -xf - -C %s", dockerBinary, name, extractionDirectory)
|
saveCmdFinal := fmt.Sprintf("%s save %s | tar -xf - -C %s", dockerBinary, name, extractionDirectory)
|
||||||
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
|
||||||
out, _, err := runCommandWithOutput(saveCmd)
|
if out, _, err := runCommandWithOutput(saveCmd); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Errorf("failed to save and extract image: %s", out)
|
t.Errorf("failed to save and extract image: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue