Browse Source

Integration cli tests on Links in inspect

Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
Alexandr Morozov 11 years ago
parent
commit
08182da5d8
2 changed files with 36 additions and 1 deletions
  1. 32 1
      integration-cli/docker_cli_links_test.go
  2. 4 0
      integration-cli/docker_utils.go

+ 32 - 1
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")
+}

+ 4 - 0
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...)