Browse code

integration-cli: DockerCLILinksSuite: replace dockerCmd and waitRun

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/07/28 01:25:39
Showing 1 changed files
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"strings"
10 10
 	"testing"
11 11
 
12
+	"github.com/docker/docker/integration-cli/cli"
12 13
 	"github.com/docker/docker/runconfig"
13 14
 	"gotest.tools/v3/assert"
14 15
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -62,8 +63,8 @@ func testLinkPingOnNetwork(c *testing.T, network string) {
62 62
 	runArgs2 := append([]string{"run", "-d", "--name", "container2", "--hostname", "wilma"}, postArgs...)
63 63
 
64 64
 	// Run the two named containers
65
-	dockerCmd(c, runArgs1...)
66
-	dockerCmd(c, runArgs2...)
65
+	cli.DockerCmd(c, runArgs1...)
66
+	cli.DockerCmd(c, runArgs2...)
67 67
 
68 68
 	postArgs = []string{}
69 69
 	if network != "" {
... ...
@@ -77,34 +78,32 @@ func testLinkPingOnNetwork(c *testing.T, network string) {
77 77
 
78 78
 	// test ping by alias, ping by name, and ping by hostname
79 79
 	// 1. Ping by alias
80
-	dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...)
80
+	cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...)
81 81
 	// 2. Ping by container name
82
-	dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...)
82
+	cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...)
83 83
 	// 3. Ping by hostname
84
-	dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
84
+	cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
85 85
 
86 86
 	// Clean for next round
87
-	dockerCmd(c, "rm", "-f", "container1")
88
-	dockerCmd(c, "rm", "-f", "container2")
87
+	cli.DockerCmd(c, "rm", "-f", "container1")
88
+	cli.DockerCmd(c, "rm", "-f", "container2")
89 89
 }
90 90
 
91 91
 func (s *DockerCLILinksSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) {
92 92
 	testRequires(c, DaemonIsLinux)
93
-	out, _ := dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
94
-	idA := strings.TrimSpace(out)
95
-	out, _ = dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
96
-	idB := strings.TrimSpace(out)
97
-	dockerCmd(c, "rename", "container1", "container_new")
98
-	dockerCmd(c, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
99
-	dockerCmd(c, "kill", idA)
100
-	dockerCmd(c, "kill", idB)
93
+	idA := cli.DockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top").Stdout()
94
+	idB := cli.DockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top").Stdout()
95
+	cli.DockerCmd(c, "rename", "container1", "container_new")
96
+	cli.DockerCmd(c, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
97
+	cli.DockerCmd(c, "kill", strings.TrimSpace(idA))
98
+	cli.DockerCmd(c, "kill", strings.TrimSpace(idB))
101 99
 }
102 100
 
103 101
 func (s *DockerCLILinksSuite) TestLinksInspectLinksStarted(c *testing.T) {
104 102
 	testRequires(c, DaemonIsLinux)
105
-	dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
106
-	dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
107
-	dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
103
+	cli.DockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
104
+	cli.DockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
105
+	cli.DockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
108 106
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
109 107
 
110 108
 	var result []string
... ...
@@ -122,9 +121,9 @@ func (s *DockerCLILinksSuite) TestLinksInspectLinksStarted(c *testing.T) {
122 122
 func (s *DockerCLILinksSuite) TestLinksInspectLinksStopped(c *testing.T) {
123 123
 	testRequires(c, DaemonIsLinux)
124 124
 
125
-	dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
126
-	dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
127
-	dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
125
+	cli.DockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
126
+	cli.DockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
127
+	cli.DockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
128 128
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
129 129
 
130 130
 	var result []string
... ...
@@ -141,22 +140,20 @@ func (s *DockerCLILinksSuite) TestLinksInspectLinksStopped(c *testing.T) {
141 141
 
142 142
 func (s *DockerCLILinksSuite) TestLinksNotStartedParentNotFail(c *testing.T) {
143 143
 	testRequires(c, DaemonIsLinux)
144
-	dockerCmd(c, "create", "--name=first", "busybox", "top")
145
-	dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top")
146
-	dockerCmd(c, "start", "first")
144
+	cli.DockerCmd(c, "create", "--name=first", "busybox", "top")
145
+	cli.DockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top")
146
+	cli.DockerCmd(c, "start", "first")
147 147
 }
148 148
 
149 149
 func (s *DockerCLILinksSuite) TestLinksHostsFilesInject(c *testing.T) {
150 150
 	testRequires(c, DaemonIsLinux)
151 151
 	testRequires(c, testEnv.IsLocalDaemon)
152 152
 
153
-	out, _ := dockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top")
154
-	idOne := strings.TrimSpace(out)
155
-
156
-	out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top")
157
-	idTwo := strings.TrimSpace(out)
158
-
159
-	assert.Assert(c, waitRun(idTwo) == nil)
153
+	idOne := cli.DockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top").Stdout()
154
+	idOne = strings.TrimSpace(idOne)
155
+	idTwo := cli.DockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top").Stdout()
156
+	idTwo = strings.TrimSpace(idTwo)
157
+	cli.WaitRun(c, idTwo)
160 158
 
161 159
 	readContainerFileWithExec(c, idOne, "/etc/hosts")
162 160
 	contentTwo := readContainerFileWithExec(c, idTwo, "/etc/hosts")
... ...
@@ -167,9 +164,9 @@ func (s *DockerCLILinksSuite) TestLinksHostsFilesInject(c *testing.T) {
167 167
 func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
168 168
 	testRequires(c, DaemonIsLinux)
169 169
 	testRequires(c, testEnv.IsLocalDaemon)
170
-	dockerCmd(c, "run", "-d", "--name", "one", "busybox", "top")
171
-	out, _ := dockerCmd(c, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top")
172
-	id := strings.TrimSpace(out)
170
+	cli.DockerCmd(c, "run", "-d", "--name", "one", "busybox", "top")
171
+	id := cli.DockerCmd(c, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top").Stdout()
172
+	id = strings.TrimSpace(id)
173 173
 
174 174
 	realIP := inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
175 175
 	content := readContainerFileWithExec(c, id, "/etc/hosts")
... ...
@@ -186,7 +183,7 @@ func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
186 186
 	ip = getIP(content, "onetwo")
187 187
 	assert.Check(c, is.Equal(ip, realIP))
188 188
 
189
-	dockerCmd(c, "restart", "one")
189
+	cli.DockerCmd(c, "restart", "one")
190 190
 	realIP = inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
191 191
 
192 192
 	content = readContainerFileWithExec(c, id, "/etc/hosts")
... ...
@@ -199,8 +196,8 @@ func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
199 199
 
200 200
 func (s *DockerCLILinksSuite) TestLinksEnvs(c *testing.T) {
201 201
 	testRequires(c, DaemonIsLinux)
202
-	dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
203
-	out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env")
202
+	cli.DockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
203
+	out := cli.DockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env").Stdout()
204 204
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e1=\n"))
205 205
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e2=v2"))
206 206
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e3=v3=v3"))
... ...
@@ -208,15 +205,13 @@ func (s *DockerCLILinksSuite) TestLinksEnvs(c *testing.T) {
208 208
 
209 209
 func (s *DockerCLILinksSuite) TestLinkShortDefinition(c *testing.T) {
210 210
 	testRequires(c, DaemonIsLinux)
211
-	out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top")
212
-
213
-	cid := strings.TrimSpace(out)
214
-	assert.Assert(c, waitRun(cid) == nil)
215
-
216
-	out, _ = dockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top")
211
+	cid := cli.DockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top").Stdout()
212
+	cid = strings.TrimSpace(cid)
213
+	cli.WaitRun(c, cid)
217 214
 
218
-	cid2 := strings.TrimSpace(out)
219
-	assert.Assert(c, waitRun(cid2) == nil)
215
+	cid2 := cli.DockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top").Stdout()
216
+	cid2 = strings.TrimSpace(cid2)
217
+	cli.WaitRun(c, cid2)
220 218
 
221 219
 	links := inspectFieldJSON(c, cid2, "HostConfig.Links")
222 220
 	assert.Equal(c, links, `["/shortlinkdef:/link2/shortlinkdef"]`)
... ...
@@ -224,7 +219,7 @@ func (s *DockerCLILinksSuite) TestLinkShortDefinition(c *testing.T) {
224 224
 
225 225
 func (s *DockerCLILinksSuite) TestLinksNetworkHostContainer(c *testing.T) {
226 226
 	testRequires(c, DaemonIsLinux, NotUserNamespace)
227
-	dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")
227
+	cli.DockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")
228 228
 	out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")
229 229
 
230 230
 	// Running container linking to a container with --net host should have failed
... ...
@@ -235,14 +230,14 @@ func (s *DockerCLILinksSuite) TestLinksNetworkHostContainer(c *testing.T) {
235 235
 
236 236
 func (s *DockerCLILinksSuite) TestLinksEtcHostsRegularFile(c *testing.T) {
237 237
 	testRequires(c, DaemonIsLinux, NotUserNamespace)
238
-	out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
238
+	out := cli.DockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts").Stdout()
239 239
 	// /etc/hosts should be a regular file
240 240
 	assert.Assert(c, is.Regexp("^-.+\n$", out))
241 241
 }
242 242
 
243 243
 func (s *DockerCLILinksSuite) TestLinksMultipleWithSameName(c *testing.T) {
244 244
 	testRequires(c, DaemonIsLinux)
245
-	dockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top")
246
-	dockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top")
247
-	dockerCmd(c, "run", "--link", "upstream-a:upstream", "--link", "upstream-b:upstream", "busybox", "sh", "-c", "ping -c 1 upstream")
245
+	cli.DockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top")
246
+	cli.DockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top")
247
+	cli.DockerCmd(c, "run", "--link", "upstream-a:upstream", "--link", "upstream-b:upstream", "busybox", "sh", "-c", "ping -c 1 upstream")
248 248
 }