diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index 0480183bc7..d2616475c9 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -2,12 +2,13 @@ package main import ( "fmt" - "github.com/dotcloud/docker/pkg/iptables" "io/ioutil" "os" "os/exec" "strings" "testing" + + "github.com/dotcloud/docker/pkg/iptables" ) func TestEtcHostsRegularFile(t *testing.T) { @@ -90,3 +91,33 @@ func TestIpTablesRulesWhenLinkAndUnlink(t *testing.T) { logDone("link - verify iptables when link and unlink") } + +func TestInspectLinksStarted(t *testing.T) { + defer deleteAllContainers() + cmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") + cmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10") + cmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sleep", "10") + links, err := inspectField("testinspectlink", "HostConfig.Links") + if err != nil { + t.Fatal(err) + } + if expected := "[/container1:/testinspectlink/alias1 /container2:/testinspectlink/alias2]"; links != expected { + t.Fatalf("Links %s, but expected %s", links, expected) + } + logDone("link - links in started container inspect") +} + +func TestInspectLinksStopped(t *testing.T) { + defer deleteAllContainers() + cmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") + cmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10") + cmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true") + links, err := inspectField("testinspectlink", "HostConfig.Links") + if err != nil { + t.Fatal(err) + } + if expected := "[/container1:/testinspectlink/alias1 /container2:/testinspectlink/alias2]"; links != expected { + t.Fatalf("Links %s, but expected %s", links, expected) + } + logDone("link - links in stopped container inspect") +} diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index c1e306f2ee..cc45012437 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -16,6 +16,10 @@ import ( func deleteContainer(container string) error { container = strings.Replace(container, "\n", " ", -1) container = strings.Trim(container, " ") + killArgs := fmt.Sprintf("kill %v", container) + killSplitArgs := strings.Split(killArgs, " ") + killCmd := exec.Command(dockerBinary, killSplitArgs...) + runCommand(killCmd) rmArgs := fmt.Sprintf("rm %v", container) rmSplitArgs := strings.Split(rmArgs, " ") rmCmd := exec.Command(dockerBinary, rmSplitArgs...)