2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
2014-04-17 22:24:19 -04:00
|
|
|
"strings"
|
2014-02-25 11:17:48 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommitAfterContainerIsDone(t *testing.T) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to run container: %v %v", out, err))
|
|
|
|
|
|
|
|
cleanedContainerID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
|
|
|
|
_, _, err = runCommandWithOutput(waitCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("error thrown while waiting for container: %s", out))
|
|
|
|
|
|
|
|
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID)
|
|
|
|
out, _, err = runCommandWithOutput(commitCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to commit container to image: %v %v", out, err))
|
|
|
|
|
|
|
|
cleanedImageID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
|
|
|
|
out, _, err = runCommandWithOutput(inspectCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to inspect image: %v %v", out, err))
|
2014-06-08 02:37:31 -04:00
|
|
|
|
|
|
|
deleteContainer(cleanedContainerID)
|
|
|
|
deleteImages(cleanedImageID)
|
|
|
|
|
|
|
|
logDone("commit - echo foo and commit the image")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommitWithoutPause(t *testing.T) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to run container: %v %v", out, err))
|
|
|
|
|
|
|
|
cleanedContainerID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
|
|
|
|
_, _, err = runCommandWithOutput(waitCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("error thrown while waiting for container: %s", out))
|
|
|
|
|
2014-06-30 20:39:38 -04:00
|
|
|
commitCmd := exec.Command(dockerBinary, "commit", "-p=false", cleanedContainerID)
|
2014-06-08 02:37:31 -04:00
|
|
|
out, _, err = runCommandWithOutput(commitCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to commit container to image: %v %v", out, err))
|
|
|
|
|
|
|
|
cleanedImageID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
|
|
|
|
out, _, err = runCommandWithOutput(inspectCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to inspect image: %v %v", out, err))
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2014-04-03 20:22:32 -04:00
|
|
|
deleteContainer(cleanedContainerID)
|
|
|
|
deleteImages(cleanedImageID)
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2014-06-30 20:39:38 -04:00
|
|
|
logDone("commit - echo foo and commit the image with --pause=false")
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2014-04-17 22:24:19 -04:00
|
|
|
|
|
|
|
func TestCommitNewFile(t *testing.T) {
|
|
|
|
cmd := exec.Command(dockerBinary, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
|
|
|
|
if _, err := runCommand(cmd); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = exec.Command(dockerBinary, "commit", "commiter")
|
2014-10-06 10:26:55 -04:00
|
|
|
imageID, _, err := runCommandWithOutput(cmd)
|
2014-04-17 22:24:19 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-10-06 10:26:55 -04:00
|
|
|
imageID = strings.Trim(imageID, "\r\n")
|
2014-04-17 22:24:19 -04:00
|
|
|
|
2014-10-06 10:26:55 -04:00
|
|
|
cmd = exec.Command(dockerBinary, "run", imageID, "cat", "/foo")
|
2014-04-17 22:24:19 -04:00
|
|
|
|
|
|
|
out, _, err := runCommandWithOutput(cmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, out)
|
|
|
|
}
|
|
|
|
if actual := strings.Trim(out, "\r\n"); actual != "koye" {
|
|
|
|
t.Fatalf("expected output koye received %s", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteAllContainers()
|
2014-10-06 10:26:55 -04:00
|
|
|
deleteImages(imageID)
|
2014-04-17 22:24:19 -04:00
|
|
|
|
|
|
|
logDone("commit - commit file and read")
|
|
|
|
}
|
2014-03-27 15:16:03 -04:00
|
|
|
|
|
|
|
func TestCommitTTY(t *testing.T) {
|
|
|
|
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
|
|
|
|
|
|
|
|
if _, err := runCommand(cmd); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = exec.Command(dockerBinary, "commit", "tty", "ttytest")
|
2014-10-06 10:26:55 -04:00
|
|
|
imageID, _, err := runCommandWithOutput(cmd)
|
2014-03-27 15:16:03 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-10-06 10:26:55 -04:00
|
|
|
imageID = strings.Trim(imageID, "\r\n")
|
2014-03-27 15:16:03 -04:00
|
|
|
|
|
|
|
cmd = exec.Command(dockerBinary, "run", "ttytest", "/bin/ls")
|
|
|
|
|
|
|
|
if _, err := runCommand(cmd); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-08-28 01:25:57 -04:00
|
|
|
|
|
|
|
logDone("commit - commit tty")
|
2014-03-27 15:16:03 -04:00
|
|
|
}
|
2014-05-19 18:57:29 -04:00
|
|
|
|
|
|
|
func TestCommitWithHostBindMount(t *testing.T) {
|
|
|
|
cmd := exec.Command(dockerBinary, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
|
|
|
|
if _, err := runCommand(cmd); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = exec.Command(dockerBinary, "commit", "bind-commit", "bindtest")
|
2014-10-06 10:26:55 -04:00
|
|
|
imageID, _, err := runCommandWithOutput(cmd)
|
2014-05-19 18:57:29 -04:00
|
|
|
if err != nil {
|
2014-10-06 10:26:55 -04:00
|
|
|
t.Fatal(imageID, err)
|
2014-05-19 18:57:29 -04:00
|
|
|
}
|
2014-10-06 10:26:55 -04:00
|
|
|
imageID = strings.Trim(imageID, "\r\n")
|
2014-05-19 18:57:29 -04:00
|
|
|
|
|
|
|
cmd = exec.Command(dockerBinary, "run", "bindtest", "true")
|
|
|
|
|
|
|
|
if _, err := runCommand(cmd); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteAllContainers()
|
2014-10-06 10:26:55 -04:00
|
|
|
deleteImages(imageID)
|
2014-05-19 18:57:29 -04:00
|
|
|
|
|
|
|
logDone("commit - commit bind mounted file")
|
|
|
|
}
|