mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #10909 from ahmetalpbalkan/run_test-defer
integration-cli: Better test cleanup with defer
This commit is contained in:
commit
b062ef05e5
16 changed files with 290 additions and 251 deletions
|
@ -14,6 +14,8 @@ import (
|
|||
)
|
||||
|
||||
func TestContainerApiGetAll(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
startCount, err := getContainerCount()
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot query container count: %v", err)
|
||||
|
@ -46,12 +48,12 @@ func TestContainerApiGetAll(t *testing.T) {
|
|||
t.Fatalf("Container Name mismatch. Expected: %q, received: %q\n", "/"+name, actual)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("container REST API - check GET json/all=1")
|
||||
}
|
||||
|
||||
func TestContainerApiGetExport(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
name := "exportcontainer"
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
|
@ -82,12 +84,13 @@ func TestContainerApiGetExport(t *testing.T) {
|
|||
if !found {
|
||||
t.Fatalf("The created test file has not been found in the exported image")
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("container REST API - check GET containers/export")
|
||||
}
|
||||
|
||||
func TestContainerApiGetChanges(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
name := "changescontainer"
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "rm", "/etc/passwd")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
|
@ -119,8 +122,6 @@ func TestContainerApiGetChanges(t *testing.T) {
|
|||
t.Fatalf("/etc/passwd has been removed but is not present in the diff")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("container REST API - check GET containers/changes")
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
)
|
||||
|
||||
func TestInspectApiContainerResponse(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -53,7 +55,5 @@ func TestInspectApiContainerResponse(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("container json - check keys in container json response")
|
||||
}
|
||||
|
|
|
@ -73,6 +73,8 @@ func TestCommitWithoutPause(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommitNewFile(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -84,6 +86,7 @@ func TestCommitNewFile(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", imageID, "cat", "/foo")
|
||||
|
||||
|
@ -95,13 +98,12 @@ func TestCommitNewFile(t *testing.T) {
|
|||
t.Fatalf("expected output koye received %q", actual)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
deleteImages(imageID)
|
||||
|
||||
logDone("commit - commit file and read")
|
||||
}
|
||||
|
||||
func TestCommitHardlink(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
|
||||
firstOuput, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
|
@ -127,6 +129,7 @@ func TestCommitHardlink(t *testing.T) {
|
|||
t.Fatal(imageID, err)
|
||||
}
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
|
||||
secondOuput, _, err := runCommandWithOutput(cmd)
|
||||
|
@ -147,9 +150,6 @@ func TestCommitHardlink(t *testing.T) {
|
|||
t.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
deleteImages(imageID)
|
||||
|
||||
logDone("commit - commit hardlinks")
|
||||
}
|
||||
|
||||
|
@ -178,6 +178,8 @@ func TestCommitTTY(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommitWithHostBindMount(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -190,6 +192,7 @@ func TestCommitWithHostBindMount(t *testing.T) {
|
|||
}
|
||||
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "bindtest", "true")
|
||||
|
||||
|
@ -197,8 +200,5 @@ func TestCommitWithHostBindMount(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
deleteImages(imageID)
|
||||
|
||||
logDone("commit - commit bind mounted file")
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ import (
|
|||
|
||||
// Make sure we can create a simple container with some args
|
||||
func TestCreateArgs(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "create", "busybox", "command", "arg1", "arg2", "arg with space")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
|
@ -56,13 +58,13 @@ func TestCreateArgs(t *testing.T) {
|
|||
t.Fatalf("Unexpected args. Expected %v, received: %v", expected, c.Args)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("create - args")
|
||||
}
|
||||
|
||||
// Make sure we can set hostconfig options too
|
||||
func TestCreateHostConfig(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "create", "-P", "busybox", "echo")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
|
@ -98,12 +100,12 @@ func TestCreateHostConfig(t *testing.T) {
|
|||
t.Fatalf("Expected PublishAllPorts, got false")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("create - hostconfig")
|
||||
}
|
||||
|
||||
func TestCreateWithPortRange(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
|
@ -147,12 +149,12 @@ func TestCreateWithPortRange(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("create - port range")
|
||||
}
|
||||
|
||||
func TestCreateWithiLargePortRange(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
|
@ -196,13 +198,13 @@ func TestCreateWithiLargePortRange(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("create - large port range")
|
||||
}
|
||||
|
||||
// "test123" should be printed by docker create + start
|
||||
func TestCreateEchoStdout(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "create", "busybox", "echo", "test123")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
|
@ -221,12 +223,12 @@ func TestCreateEchoStdout(t *testing.T) {
|
|||
t.Errorf("container should've printed 'test123', got %q", out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("create - echo test123")
|
||||
}
|
||||
|
||||
func TestCreateVolumesCreated(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
name := "test_create_volume"
|
||||
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "create", "--name", name, "-v", "/foo", "busybox")); err != nil {
|
||||
t.Fatal(out, err)
|
||||
|
|
|
@ -137,6 +137,8 @@ func TestDaemonStartBridgeWithoutIPAssociation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDaemonIptablesClean(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
d := NewDaemon(t)
|
||||
if err := d.StartWithBusybox(); err != nil {
|
||||
t.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
|
@ -174,12 +176,12 @@ func TestDaemonIptablesClean(t *testing.T) {
|
|||
t.Fatalf("iptables output should not have contained %q, but was %q", ipTablesSearchString, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("daemon - run,iptables - iptables rules cleaned after daemon restart")
|
||||
}
|
||||
|
||||
func TestDaemonIptablesCreate(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
d := NewDaemon(t)
|
||||
if err := d.StartWithBusybox(); err != nil {
|
||||
t.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
|
@ -226,8 +228,6 @@ func TestDaemonIptablesCreate(t *testing.T) {
|
|||
t.Fatalf("iptables output after restart should have contained %q, but was %q", ipTablesSearchString, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("daemon - run,iptables - iptables rules for always restarted container created after daemon restart")
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ import (
|
|||
)
|
||||
|
||||
func TestExec(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100")
|
||||
if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
|
||||
t.Fatal(out, err)
|
||||
|
@ -34,8 +36,6 @@ func TestExec(t *testing.T) {
|
|||
t.Errorf("container exec should've printed %q but printed %q", expected, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("exec - basic test")
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,8 @@ func TestExecInteractiveStdinClose(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExecInteractive(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100")
|
||||
if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
|
||||
t.Fatal(out, err)
|
||||
|
@ -127,12 +129,12 @@ func TestExecInteractive(t *testing.T) {
|
|||
t.Fatal("docker exec failed to exit on stdin close")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("exec - Interactive test")
|
||||
}
|
||||
|
||||
func TestExecAfterContainerRestart(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -157,12 +159,12 @@ func TestExecAfterContainerRestart(t *testing.T) {
|
|||
t.Errorf("container should've printed hello, instead printed %q", outStr)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("exec - exec running container after container restart")
|
||||
}
|
||||
|
||||
func TestExecAfterDaemonRestart(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
d := NewDaemon(t)
|
||||
if err := d.StartWithBusybox(); err != nil {
|
||||
t.Fatalf("Could not start daemon with busybox: %v", err)
|
||||
|
@ -222,6 +224,8 @@ func TestExecEnv(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExecExitStatus(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
|
||||
if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
|
||||
t.Fatal(out, err)
|
||||
|
@ -239,7 +243,6 @@ func TestExecExitStatus(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExecPausedContainer(t *testing.T) {
|
||||
|
||||
defer deleteAllContainers()
|
||||
defer unpauseAllContainers()
|
||||
|
||||
|
@ -493,6 +496,8 @@ func TestInspectExecID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLinksPingLinkedContainersOnRename(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
var out string
|
||||
out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
|
||||
idA := stripTrailingCharacters(out)
|
||||
|
@ -519,8 +524,6 @@ func TestLinksPingLinkedContainersOnRename(t *testing.T) {
|
|||
t.Fatal(out, err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("links - ping linked container upon rename")
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import (
|
|||
)
|
||||
|
||||
func TestLinksEtcHostsRegularFile(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
|
@ -24,13 +26,12 @@ func TestLinksEtcHostsRegularFile(t *testing.T) {
|
|||
if !strings.HasPrefix(out, "-") {
|
||||
t.Errorf("/etc/hosts should be a regular file")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("link - /etc/hosts is a regular file")
|
||||
}
|
||||
|
||||
func TestLinksEtcHostsContentMatch(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
testRequires(t, SameHostDaemon)
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts")
|
||||
|
@ -48,8 +49,6 @@ func TestLinksEtcHostsContentMatch(t *testing.T) {
|
|||
t.Errorf("container")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("link - /etc/hosts matches hosts copy")
|
||||
}
|
||||
|
||||
|
@ -68,6 +67,8 @@ func TestLinksPingUnlinkedContainers(t *testing.T) {
|
|||
|
||||
// Test for appropriate error when calling --link with an invalid target container
|
||||
func TestLinksInvalidContainerTarget(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--link", "bogus:alias", "busybox", "true")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
|
||||
|
@ -77,12 +78,13 @@ func TestLinksInvalidContainerTarget(t *testing.T) {
|
|||
if !strings.Contains(out, "Could not get container") {
|
||||
t.Fatal("error output expected 'Could not get container', but got %q instead; err: %v", out, err)
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("links - linking to non-existent container should not work")
|
||||
}
|
||||
|
||||
func TestLinksPingLinkedContainers(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top")
|
||||
if _, err := runCommand(runCmd); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -103,11 +105,12 @@ func TestLinksPingLinkedContainers(t *testing.T) {
|
|||
// 3. Ping by hostname
|
||||
dockerCmd(t, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
|
||||
|
||||
deleteAllContainers()
|
||||
logDone("links - ping linked container")
|
||||
}
|
||||
|
||||
func TestLinksPingLinkedContainersAfterRename(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
out, _, _ := dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
|
||||
idA := stripTrailingCharacters(out)
|
||||
out, _, _ = dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
|
||||
|
@ -116,12 +119,13 @@ func TestLinksPingLinkedContainersAfterRename(t *testing.T) {
|
|||
dockerCmd(t, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
|
||||
dockerCmd(t, "kill", idA)
|
||||
dockerCmd(t, "kill", idB)
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("links - ping linked container after rename")
|
||||
}
|
||||
|
||||
func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
testRequires(t, SameHostDaemon)
|
||||
|
||||
dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10")
|
||||
|
@ -143,7 +147,6 @@ func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
|
|||
|
||||
dockerCmd(t, "kill", "child")
|
||||
dockerCmd(t, "kill", "parent")
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("link - verify iptables when link and unlink")
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
func TestNetworkNat(t *testing.T) {
|
||||
testRequires(t, SameHostDaemon)
|
||||
defer deleteAllContainers()
|
||||
|
||||
iface, err := net.InterfaceByName("eth0")
|
||||
if err != nil {
|
||||
|
@ -56,7 +57,6 @@ func TestNetworkNat(t *testing.T) {
|
|||
if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
||||
t.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("network - make sure nat works through the host")
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
)
|
||||
|
||||
func TestPortList(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
// one port
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
|
@ -121,8 +123,6 @@ func TestPortList(t *testing.T) {
|
|||
t.Fatal(out, err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("port - test port list")
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ import (
|
|||
)
|
||||
|
||||
func TestPsListContainers(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -223,8 +225,6 @@ func TestPsListContainers(t *testing.T) {
|
|||
t.Error("Container list is not in the correct order")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("ps - test ps options")
|
||||
}
|
||||
|
||||
|
@ -246,6 +246,8 @@ func assertContainerList(out string, expected []string) bool {
|
|||
}
|
||||
|
||||
func TestPsListContainersSize(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
|
||||
runCommandWithOutput(cmd)
|
||||
cmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
||||
|
@ -296,14 +298,14 @@ func TestPsListContainersSize(t *testing.T) {
|
|||
t.Fatalf("Expected size %q, got %q", expectedSize, foundSize)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
logDone("ps - test ps size")
|
||||
}
|
||||
|
||||
func TestPsListContainersFilterStatus(t *testing.T) {
|
||||
// FIXME: this should test paused, but it makes things hang and its wonky
|
||||
// this is because paused containers can't be controlled by signals
|
||||
deleteAllContainers()
|
||||
defer deleteAllContainers()
|
||||
|
||||
// start exited container
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
|
@ -347,12 +349,12 @@ func TestPsListContainersFilterStatus(t *testing.T) {
|
|||
t.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("ps - test ps filter status")
|
||||
}
|
||||
|
||||
func TestPsListContainersFilterID(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
// start container
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
|
@ -377,12 +379,12 @@ func TestPsListContainersFilterID(t *testing.T) {
|
|||
t.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("ps - test ps filter id")
|
||||
}
|
||||
|
||||
func TestPsListContainersFilterName(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
// start container
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name=a_name_to_match", "busybox")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
|
@ -407,8 +409,6 @@ func TestPsListContainersFilterName(t *testing.T) {
|
|||
t.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("ps - test ps filter name")
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
)
|
||||
|
||||
func TestRenameStoppedContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -36,12 +38,13 @@ func TestRenameStoppedContainer(t *testing.T) {
|
|||
if name != "new_name" {
|
||||
t.Fatal("Failed to rename container ", name)
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rename - stopped container")
|
||||
}
|
||||
|
||||
func TestRenameRunningContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -62,12 +65,13 @@ func TestRenameRunningContainer(t *testing.T) {
|
|||
if name != "new_name" {
|
||||
t.Fatal("Failed to rename container ")
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rename - running container")
|
||||
}
|
||||
|
||||
func TestRenameCheckNames(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -93,8 +97,6 @@ func TestRenameCheckNames(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rename - running container")
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
)
|
||||
|
||||
func TestRestartStoppedContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "foobar")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -46,12 +48,12 @@ func TestRestartStoppedContainer(t *testing.T) {
|
|||
t.Errorf("container should've printed 'foobar' twice")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("restart - echo foobar for stopped container")
|
||||
}
|
||||
|
||||
func TestRestartRunningContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -89,13 +91,13 @@ func TestRestartRunningContainer(t *testing.T) {
|
|||
t.Errorf("container should've printed 'foobar' twice")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("restart - echo foobar for running container")
|
||||
}
|
||||
|
||||
// Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819.
|
||||
func TestRestartWithVolumes(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/test", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
@ -147,8 +149,6 @@ func TestRestartWithVolumes(t *testing.T) {
|
|||
t.Errorf("expected volume path: %s Actual path: %s", volumes, volumesAfterRestart)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("restart - does not create a new volume on restart")
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
)
|
||||
|
||||
func TestRmContainerWithRemovedVolume(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -22,12 +24,12 @@ func TestRmContainerWithRemovedVolume(t *testing.T) {
|
|||
t.Fatal(out, err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rm - removed volume")
|
||||
}
|
||||
|
||||
func TestRmContainerWithVolume(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", "foo", "-v", "/srv", "busybox", "true")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -38,12 +40,12 @@ func TestRmContainerWithVolume(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rm - volume")
|
||||
}
|
||||
|
||||
func TestRmRunningContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
createRunningContainer(t, "foo")
|
||||
|
||||
// Test cannot remove running container
|
||||
|
@ -52,12 +54,12 @@ func TestRmRunningContainer(t *testing.T) {
|
|||
t.Fatalf("Expected error, can't rm a running container")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rm - running container")
|
||||
}
|
||||
|
||||
func TestRmRunningContainerCheckError409(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
createRunningContainer(t, "foo")
|
||||
|
||||
endpoint := "/containers/foo"
|
||||
|
@ -70,12 +72,12 @@ func TestRmRunningContainerCheckError409(t *testing.T) {
|
|||
t.Fatalf("Expected error to contain '409 Conflict' but found %s", err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rm - running container")
|
||||
}
|
||||
|
||||
func TestRmForceRemoveRunningContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
createRunningContainer(t, "foo")
|
||||
|
||||
// Stop then remove with -s
|
||||
|
@ -84,12 +86,12 @@ func TestRmForceRemoveRunningContainer(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rm - running container with --force=true")
|
||||
}
|
||||
|
||||
func TestRmContainerOrphaning(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
dockerfile1 := `FROM busybox:latest
|
||||
ENTRYPOINT ["/bin/true"]`
|
||||
img := "test-container-orphaning"
|
||||
|
@ -99,6 +101,7 @@ func TestRmContainerOrphaning(t *testing.T) {
|
|||
|
||||
// build first dockerfile
|
||||
img1, err := buildImage(img, dockerfile1, true)
|
||||
defer deleteImages(img1)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not build image %s: %v", img, err)
|
||||
}
|
||||
|
@ -123,9 +126,6 @@ func TestRmContainerOrphaning(t *testing.T) {
|
|||
t.Fatalf("Orphaned container (could not find %q in docker images): %s", img1, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
deleteImages(img1)
|
||||
|
||||
logDone("rm - container orphaning")
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,8 @@ func TestRmiTag(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRmiTagWithExistingContainers(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
container := "test-delete-tag"
|
||||
newtag := "busybox:newtag"
|
||||
bb := "busybox:latest"
|
||||
|
@ -95,12 +97,12 @@ func TestRmiTagWithExistingContainers(t *testing.T) {
|
|||
t.Fatalf("Expected 1 untagged entry got %d: %q", d, out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rmi - delete tag with existing containers")
|
||||
}
|
||||
|
||||
func TestRmiForceWithExistingContainers(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
image := "busybox-clone"
|
||||
|
||||
cmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", image, "-")
|
||||
|
@ -120,7 +122,5 @@ MAINTAINER foo`)
|
|||
t.Fatalf("Could not remove image %s: %s, %v", image, out, err)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("rmi - force delete with existing containers")
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -56,6 +56,8 @@ func TestRunRedirectStdout(t *testing.T) {
|
|||
|
||||
// Test recursive bind mount works by default
|
||||
func TestRunWithVolumesIsRecursive(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "docker_recursive_mount_test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -87,7 +89,5 @@ func TestRunWithVolumesIsRecursive(t *testing.T) {
|
|||
t.Fatal("Recursive bind mount test failed. Expected file not found")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - volumes are bind mounted recursively")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue