Skip to content

Commit

Permalink
add a test using the flags
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
  • Loading branch information
vieux committed Jun 17, 2014
1 parent 614c57c commit 6228761
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions integration-cli/docker_cli_save_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"
)

// save a repo and try to load it
func TestSaveAndLoadRepo(t *testing.T) {
// save a repo and try to load it using stdout
func TestSaveAndLoadRepoStdout(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, fmt.Sprintf("failed to create a container: %v %v", out, err))
Expand Down Expand Up @@ -55,6 +55,58 @@ func TestSaveAndLoadRepo(t *testing.T) {

os.Remove("/tmp/foobar-save-load-test.tar")

logDone("save - save a repo")
logDone("load - load a repo")
logDone("save - save a repo using stdout")
logDone("load - load a repo using stdout")
}

// save a repo and try to load it using flags
func TestSaveAndLoadRepoFlags(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, fmt.Sprintf("failed to create a container: %v %v", out, err))

cleanedContainerID := stripTrailingCharacters(out)

repoName := "foobar-save-load-test"

inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
out, _, err = runCommandWithOutput(inspectCmd)
errorOut(err, t, fmt.Sprintf("output should've been a container id: %v %v", cleanedContainerID, err))

commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
out, _, err = runCommandWithOutput(commitCmd)
errorOut(err, t, fmt.Sprintf("failed to commit container: %v %v", out, err))

inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
before, _, err := runCommandWithOutput(inspectCmd)
errorOut(err, t, fmt.Sprintf("the repo should exist before saving it: %v %v", before, err))

saveCmdTemplate := `%v save -o /tmp/foobar-save-load-test.tar %v`
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName)
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
out, _, err = runCommandWithOutput(saveCmd)
errorOut(err, t, fmt.Sprintf("failed to save repo: %v %v", out, err))

deleteImages(repoName)

loadCmdFinal := `docker load -i /tmp/foobar-save-load-test.tar`
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
out, _, err = runCommandWithOutput(loadCmd)
errorOut(err, t, fmt.Sprintf("failed to load repo: %v %v", out, err))

inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
after, _, err := runCommandWithOutput(inspectCmd)
errorOut(err, t, fmt.Sprintf("the repo should exist after loading it: %v %v", after, err))

if before != after {
t.Fatalf("inspect is not the same after a save / load")
}

deleteContainer(cleanedContainerID)
deleteImages(repoName)

os.Remove("/tmp/foobar-save-load-test.tar")

logDone("save - save a repo using -o")
logDone("load - load a repo using -i")
}

0 comments on commit 6228761

Please sign in to comment.