|
@@ -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")
|
|
|
}
|