Browse code

Integration cli tests on Links in inspect

Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)

Alexandr Morozov authored on 2014/06/27 17:26:02
Showing 2 changed files
... ...
@@ -2,12 +2,13 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"github.com/dotcloud/docker/pkg/iptables"
6 5
 	"io/ioutil"
7 6
 	"os"
8 7
 	"os/exec"
9 8
 	"strings"
10 9
 	"testing"
10
+
11
+	"github.com/dotcloud/docker/pkg/iptables"
11 12
 )
12 13
 
13 14
 func TestEtcHostsRegularFile(t *testing.T) {
... ...
@@ -90,3 +91,33 @@ func TestIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
90 90
 
91 91
 	logDone("link - verify iptables when link and unlink")
92 92
 }
93
+
94
+func TestInspectLinksStarted(t *testing.T) {
95
+	defer deleteAllContainers()
96
+	cmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
97
+	cmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
98
+	cmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sleep", "10")
99
+	links, err := inspectField("testinspectlink", "HostConfig.Links")
100
+	if err != nil {
101
+		t.Fatal(err)
102
+	}
103
+	if expected := "[/container1:/testinspectlink/alias1 /container2:/testinspectlink/alias2]"; links != expected {
104
+		t.Fatalf("Links %s, but expected %s", links, expected)
105
+	}
106
+	logDone("link - links in started container inspect")
107
+}
108
+
109
+func TestInspectLinksStopped(t *testing.T) {
110
+	defer deleteAllContainers()
111
+	cmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
112
+	cmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
113
+	cmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
114
+	links, err := inspectField("testinspectlink", "HostConfig.Links")
115
+	if err != nil {
116
+		t.Fatal(err)
117
+	}
118
+	if expected := "[/container1:/testinspectlink/alias1 /container2:/testinspectlink/alias2]"; links != expected {
119
+		t.Fatalf("Links %s, but expected %s", links, expected)
120
+	}
121
+	logDone("link - links in stopped container inspect")
122
+}
... ...
@@ -16,6 +16,10 @@ import (
16 16
 func deleteContainer(container string) error {
17 17
 	container = strings.Replace(container, "\n", " ", -1)
18 18
 	container = strings.Trim(container, " ")
19
+	killArgs := fmt.Sprintf("kill %v", container)
20
+	killSplitArgs := strings.Split(killArgs, " ")
21
+	killCmd := exec.Command(dockerBinary, killSplitArgs...)
22
+	runCommand(killCmd)
19 23
 	rmArgs := fmt.Sprintf("rm %v", container)
20 24
 	rmSplitArgs := strings.Split(rmArgs, " ")
21 25
 	rmCmd := exec.Command(dockerBinary, rmSplitArgs...)