Part of #14603
integration-cli/docker_cli_links_test.go (coolljt0725)
integration-cli/docker_cli_links_unix_test.go (coolljt0725)
integration-cli/docker_cli_logs_test.go (coolljt0725)
integration-cli/docker_cli_nat_test.go (coolljt0725)
integration-cli/docker_cli_network_test.go (coolljt0725)
integration-cli/docker_cli_stats_test.go (coolljt0725)
integration-cli/docker_cli_tag_test.go (coolljt0725)
integration-cli/docker_cli_top_test.go (coolljt0725)
integration-cli/docker_cli_version_test.go (coolljt0725)
integration-cli/docker_cli_wait_test.go (coolljt0725
Signed-off-by: Lei Jitang <leijitang@huawei.com>
... | ... |
@@ -2,18 +2,16 @@ package main |
2 | 2 |
|
3 | 3 |
import ( |
4 | 4 |
"fmt" |
5 |
- "os/exec" |
|
5 |
+ "github.com/go-check/check" |
|
6 | 6 |
"reflect" |
7 | 7 |
"regexp" |
8 | 8 |
"strings" |
9 | 9 |
"time" |
10 |
- |
|
11 |
- "github.com/go-check/check" |
|
12 | 10 |
) |
13 | 11 |
|
14 | 12 |
func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) { |
15 |
- runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") |
|
16 |
- exitCode, err := runCommand(runCmd) |
|
13 |
+ |
|
14 |
+ _, exitCode, err := dockerCmdWithError(c, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") |
|
17 | 15 |
|
18 | 16 |
if exitCode == 0 { |
19 | 17 |
c.Fatal("run ping did not fail") |
... | ... |
@@ -26,8 +24,7 @@ func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) { |
26 | 26 |
// Test for appropriate error when calling --link with an invalid target container |
27 | 27 |
func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) { |
28 | 28 |
|
29 |
- runCmd := exec.Command(dockerBinary, "run", "--link", "bogus:alias", "busybox", "true") |
|
30 |
- out, _, err := runCommandWithOutput(runCmd) |
|
29 |
+ out, _, err := dockerCmdWithError(c, "run", "--link", "bogus:alias", "busybox", "true") |
|
31 | 30 |
|
32 | 31 |
if err == nil { |
33 | 32 |
c.Fatal("an invalid container target should produce an error") |
... | ... |
@@ -40,14 +37,8 @@ func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) { |
40 | 40 |
|
41 | 41 |
func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) { |
42 | 42 |
|
43 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top") |
|
44 |
- if _, err := runCommand(runCmd); err != nil { |
|
45 |
- c.Fatal(err) |
|
46 |
- } |
|
47 |
- runCmd = exec.Command(dockerBinary, "run", "-d", "--name", "container2", "--hostname", "wilma", "busybox", "top") |
|
48 |
- if _, err := runCommand(runCmd); err != nil { |
|
49 |
- c.Fatal(err) |
|
50 |
- } |
|
43 |
+ dockerCmd(c, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top") |
|
44 |
+ dockerCmd(c, "run", "-d", "--name", "container2", "--hostname", "wilma", "busybox", "top") |
|
51 | 45 |
|
52 | 46 |
runArgs := []string{"run", "--rm", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sh", "-c"} |
53 | 47 |
pingCmd := "ping -c 1 %s -W 1 && ping -c 1 %s -W 1" |
... | ... |
@@ -131,38 +122,20 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) { |
131 | 131 |
} |
132 | 132 |
|
133 | 133 |
func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) { |
134 |
- runCmd := exec.Command(dockerBinary, "create", "--name=first", "busybox", "top") |
|
135 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
136 |
- if err != nil { |
|
137 |
- c.Fatal(out, err) |
|
138 |
- } |
|
139 |
- runCmd = exec.Command(dockerBinary, "create", "--name=second", "--link=first:first", "busybox", "top") |
|
140 |
- out, _, _, err = runCommandWithStdoutStderr(runCmd) |
|
141 |
- if err != nil { |
|
142 |
- c.Fatal(out, err) |
|
143 |
- } |
|
144 |
- runCmd = exec.Command(dockerBinary, "start", "first") |
|
145 |
- out, _, _, err = runCommandWithStdoutStderr(runCmd) |
|
146 |
- if err != nil { |
|
147 |
- c.Fatal(out, err) |
|
148 |
- } |
|
134 |
+ |
|
135 |
+ dockerCmd(c, "create", "--name=first", "busybox", "top") |
|
136 |
+ dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top") |
|
137 |
+ dockerCmd(c, "start", "first") |
|
138 |
+ |
|
149 | 139 |
} |
150 | 140 |
|
151 | 141 |
func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) { |
152 | 142 |
testRequires(c, SameHostDaemon, ExecSupport) |
153 | 143 |
|
154 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "one", "busybox", "top")) |
|
155 |
- if err != nil { |
|
156 |
- c.Fatal(err, out) |
|
157 |
- } |
|
158 |
- |
|
144 |
+ out, _ := dockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top") |
|
159 | 145 |
idOne := strings.TrimSpace(out) |
160 | 146 |
|
161 |
- out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top")) |
|
162 |
- if err != nil { |
|
163 |
- c.Fatal(err, out) |
|
164 |
- } |
|
165 |
- |
|
147 |
+ out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top") |
|
166 | 148 |
idTwo := strings.TrimSpace(out) |
167 | 149 |
|
168 | 150 |
time.Sleep(1 * time.Second) |
... | ... |
@@ -185,14 +158,8 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) { |
185 | 185 |
|
186 | 186 |
func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { |
187 | 187 |
testRequires(c, SameHostDaemon, ExecSupport) |
188 |
- |
|
189 |
- if out, err := exec.Command(dockerBinary, "run", "-d", "--name", "one", "busybox", "top").CombinedOutput(); err != nil { |
|
190 |
- c.Fatal(err, string(out)) |
|
191 |
- } |
|
192 |
- out, err := exec.Command(dockerBinary, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top").CombinedOutput() |
|
193 |
- if err != nil { |
|
194 |
- c.Fatal(err, string(out)) |
|
195 |
- } |
|
188 |
+ dockerCmd(c, "run", "-d", "--name", "one", "busybox", "top") |
|
189 |
+ out, _ := dockerCmd(c, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top") |
|
196 | 190 |
id := strings.TrimSpace(string(out)) |
197 | 191 |
|
198 | 192 |
realIP, err := inspectField("one", "NetworkSettings.IPAddress") |
... | ... |
@@ -217,9 +184,7 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { |
217 | 217 |
if ip := getIP(content, "onetwo"); ip != realIP { |
218 | 218 |
c.Fatalf("For 'onetwo' alias expected IP: %s, got: %s", realIP, ip) |
219 | 219 |
} |
220 |
- if out, err := exec.Command(dockerBinary, "restart", "one").CombinedOutput(); err != nil { |
|
221 |
- c.Fatal(err, string(out)) |
|
222 |
- } |
|
220 |
+ dockerCmd(c, "restart", "one") |
|
223 | 221 |
realIP, err = inspectField("one", "NetworkSettings.IPAddress") |
224 | 222 |
if err != nil { |
225 | 223 |
c.Fatal(err) |
... | ... |
@@ -237,19 +202,8 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { |
237 | 237 |
} |
238 | 238 |
|
239 | 239 |
func (s *DockerSuite) TestLinksEnvs(c *check.C) { |
240 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top") |
|
241 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
242 |
- if err != nil { |
|
243 |
- c.Fatalf("Run of first failed: %s\n%s", out, err) |
|
244 |
- } |
|
245 |
- |
|
246 |
- runCmd = exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "busybox", "env") |
|
247 |
- |
|
248 |
- out, stde, rc, err := runCommandWithStdoutStderr(runCmd) |
|
249 |
- if err != nil || rc != 0 { |
|
250 |
- c.Fatalf("run of 2nd failed: rc: %d, out: %s\n err: %s", rc, out, stde) |
|
251 |
- } |
|
252 |
- |
|
240 |
+ dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top") |
|
241 |
+ out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env") |
|
253 | 242 |
if !strings.Contains(out, "FIRST_ENV_e1=\n") || |
254 | 243 |
!strings.Contains(out, "FIRST_ENV_e2=v2") || |
255 | 244 |
!strings.Contains(out, "FIRST_ENV_e3=v3=v3") { |
... | ... |
@@ -258,16 +212,12 @@ func (s *DockerSuite) TestLinksEnvs(c *check.C) { |
258 | 258 |
} |
259 | 259 |
|
260 | 260 |
func (s *DockerSuite) TestLinkShortDefinition(c *check.C) { |
261 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "shortlinkdef", "busybox", "top") |
|
262 |
- out, _, err := runCommandWithOutput(runCmd) |
|
263 |
- c.Assert(err, check.IsNil) |
|
261 |
+ out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top") |
|
264 | 262 |
|
265 | 263 |
cid := strings.TrimSpace(out) |
266 | 264 |
c.Assert(waitRun(cid), check.IsNil) |
267 | 265 |
|
268 |
- runCmd = exec.Command(dockerBinary, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top") |
|
269 |
- out, _, err = runCommandWithOutput(runCmd) |
|
270 |
- c.Assert(err, check.IsNil) |
|
266 |
+ out, _ = dockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top") |
|
271 | 267 |
|
272 | 268 |
cid2 := strings.TrimSpace(out) |
273 | 269 |
c.Assert(waitRun(cid2), check.IsNil) |
... | ... |
@@ -5,19 +5,13 @@ package main |
5 | 5 |
import ( |
6 | 6 |
"io/ioutil" |
7 | 7 |
"os" |
8 |
- "os/exec" |
|
9 | 8 |
"strings" |
10 | 9 |
|
11 | 10 |
"github.com/go-check/check" |
12 | 11 |
) |
13 | 12 |
|
14 | 13 |
func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) { |
15 |
- runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") |
|
16 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
17 |
- if err != nil { |
|
18 |
- c.Fatal(out, err) |
|
19 |
- } |
|
20 |
- |
|
14 |
+ out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") |
|
21 | 15 |
if !strings.HasPrefix(out, "-") { |
22 | 16 |
c.Errorf("/etc/hosts should be a regular file") |
23 | 17 |
} |
... | ... |
@@ -26,12 +20,7 @@ func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) { |
26 | 26 |
func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) { |
27 | 27 |
testRequires(c, SameHostDaemon) |
28 | 28 |
|
29 |
- runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts") |
|
30 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
31 |
- if err != nil { |
|
32 |
- c.Fatal(out, err) |
|
33 |
- } |
|
34 |
- |
|
29 |
+ out, _ := dockerCmd(c, "run", "--net=host", "busybox", "cat", "/etc/hosts") |
|
35 | 30 |
hosts, err := ioutil.ReadFile("/etc/hosts") |
36 | 31 |
if os.IsNotExist(err) { |
37 | 32 |
c.Skip("/etc/hosts does not exist, skip this test") |
... | ... |
@@ -44,13 +33,8 @@ func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) { |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) { |
47 |
- |
|
48 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")) |
|
49 |
- if err != nil { |
|
50 |
- c.Fatal(err, out) |
|
51 |
- } |
|
52 |
- |
|
53 |
- out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")) |
|
47 |
+ dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top") |
|
48 |
+ out, _, err := dockerCmdWithError(c, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true") |
|
54 | 49 |
if err == nil || !strings.Contains(out, "--net=host can't be used with links. This would result in undefined behavior") { |
55 | 50 |
c.Fatalf("Running container linking to a container with --net host should have failed: %s", out) |
56 | 51 |
} |
... | ... |
@@ -17,21 +17,11 @@ import ( |
17 | 17 |
// This used to work, it test a log of PageSize-1 (gh#4851) |
18 | 18 |
func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *check.C) { |
19 | 19 |
testLen := 32767 |
20 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen)) |
|
21 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
22 |
- if err != nil { |
|
23 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
24 |
- } |
|
25 |
- |
|
20 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen)) |
|
26 | 21 |
cleanedContainerID := strings.TrimSpace(out) |
27 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
28 |
- |
|
29 |
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
30 |
- out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
31 |
- if err != nil { |
|
32 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
33 |
- } |
|
34 | 22 |
|
23 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
24 |
+ out, _ = dockerCmd(c, "logs", cleanedContainerID) |
|
35 | 25 |
if len(out) != testLen+1 { |
36 | 26 |
c.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out)) |
37 | 27 |
} |
... | ... |
@@ -40,20 +30,12 @@ func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *check.C) { |
40 | 40 |
// Regression test: When going over the PageSize, it used to panic (gh#4851) |
41 | 41 |
func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *check.C) { |
42 | 42 |
testLen := 32768 |
43 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen)) |
|
44 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
45 |
- if err != nil { |
|
46 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
47 |
- } |
|
43 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen)) |
|
48 | 44 |
|
49 | 45 |
cleanedContainerID := strings.TrimSpace(out) |
50 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
46 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
51 | 47 |
|
52 |
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
53 |
- out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
54 |
- if err != nil { |
|
55 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
56 |
- } |
|
48 |
+ out, _ = dockerCmd(c, "logs", cleanedContainerID) |
|
57 | 49 |
|
58 | 50 |
if len(out) != testLen+1 { |
59 | 51 |
c.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out)) |
... | ... |
@@ -63,20 +45,12 @@ func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *check.C) { |
63 | 63 |
// Regression test: When going much over the PageSize, it used to block (gh#4851) |
64 | 64 |
func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *check.C) { |
65 | 65 |
testLen := 33000 |
66 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen)) |
|
67 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
68 |
- if err != nil { |
|
69 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
70 |
- } |
|
66 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen)) |
|
71 | 67 |
|
72 | 68 |
cleanedContainerID := strings.TrimSpace(out) |
73 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
69 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
74 | 70 |
|
75 |
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
76 |
- out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
77 |
- if err != nil { |
|
78 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
79 |
- } |
|
71 |
+ out, _ = dockerCmd(c, "logs", cleanedContainerID) |
|
80 | 72 |
|
81 | 73 |
if len(out) != testLen+1 { |
82 | 74 |
c.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out)) |
... | ... |
@@ -85,21 +59,12 @@ func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *check.C) { |
85 | 85 |
|
86 | 86 |
func (s *DockerSuite) TestLogsTimestamps(c *check.C) { |
87 | 87 |
testLen := 100 |
88 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)) |
|
89 |
- |
|
90 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
91 |
- if err != nil { |
|
92 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
93 |
- } |
|
88 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)) |
|
94 | 89 |
|
95 | 90 |
cleanedContainerID := strings.TrimSpace(out) |
96 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
91 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
97 | 92 |
|
98 |
- logsCmd := exec.Command(dockerBinary, "logs", "-t", cleanedContainerID) |
|
99 |
- out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
100 |
- if err != nil { |
|
101 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
102 |
- } |
|
93 |
+ out, _ = dockerCmd(c, "logs", "-t", cleanedContainerID) |
|
103 | 94 |
|
104 | 95 |
lines := strings.Split(out, "\n") |
105 | 96 |
|
... | ... |
@@ -124,21 +89,12 @@ func (s *DockerSuite) TestLogsTimestamps(c *check.C) { |
124 | 124 |
|
125 | 125 |
func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) { |
126 | 126 |
msg := "stderr_log" |
127 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)) |
|
128 |
- |
|
129 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
130 |
- if err != nil { |
|
131 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
132 |
- } |
|
127 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)) |
|
133 | 128 |
|
134 | 129 |
cleanedContainerID := strings.TrimSpace(out) |
135 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
130 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
136 | 131 |
|
137 |
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
138 |
- stdout, stderr, _, err := runCommandWithStdoutStderr(logsCmd) |
|
139 |
- if err != nil { |
|
140 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
141 |
- } |
|
132 |
+ stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", cleanedContainerID) |
|
142 | 133 |
|
143 | 134 |
if stdout != "" { |
144 | 135 |
c.Fatalf("Expected empty stdout stream, got %v", stdout) |
... | ... |
@@ -152,22 +108,12 @@ func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) { |
152 | 152 |
|
153 | 153 |
func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) { |
154 | 154 |
msg := "stderr_log" |
155 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)) |
|
156 |
- |
|
157 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
158 |
- if err != nil { |
|
159 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
160 |
- } |
|
155 |
+ out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)) |
|
161 | 156 |
|
162 | 157 |
cleanedContainerID := strings.TrimSpace(out) |
163 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
164 |
- |
|
165 |
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
166 |
- stdout, stderr, _, err := runCommandWithStdoutStderr(logsCmd) |
|
167 |
- if err != nil { |
|
168 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
169 |
- } |
|
158 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
170 | 159 |
|
160 |
+ stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", cleanedContainerID) |
|
171 | 161 |
if stderr != "" { |
172 | 162 |
c.Fatalf("Expected empty stderr stream, got %v", stdout) |
173 | 163 |
} |
... | ... |
@@ -180,45 +126,26 @@ func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) { |
180 | 180 |
|
181 | 181 |
func (s *DockerSuite) TestLogsTail(c *check.C) { |
182 | 182 |
testLen := 100 |
183 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)) |
|
184 |
- |
|
185 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
186 |
- if err != nil { |
|
187 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
188 |
- } |
|
183 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)) |
|
189 | 184 |
|
190 | 185 |
cleanedContainerID := strings.TrimSpace(out) |
191 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
186 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
192 | 187 |
|
193 |
- logsCmd := exec.Command(dockerBinary, "logs", "--tail", "5", cleanedContainerID) |
|
194 |
- out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
195 |
- if err != nil { |
|
196 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
197 |
- } |
|
188 |
+ out, _ = dockerCmd(c, "logs", "--tail", "5", cleanedContainerID) |
|
198 | 189 |
|
199 | 190 |
lines := strings.Split(out, "\n") |
200 | 191 |
|
201 | 192 |
if len(lines) != 6 { |
202 | 193 |
c.Fatalf("Expected log %d lines, received %d\n", 6, len(lines)) |
203 | 194 |
} |
204 |
- |
|
205 |
- logsCmd = exec.Command(dockerBinary, "logs", "--tail", "all", cleanedContainerID) |
|
206 |
- out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
207 |
- if err != nil { |
|
208 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
209 |
- } |
|
195 |
+ out, _ = dockerCmd(c, "logs", "--tail", "all", cleanedContainerID) |
|
210 | 196 |
|
211 | 197 |
lines = strings.Split(out, "\n") |
212 | 198 |
|
213 | 199 |
if len(lines) != testLen+1 { |
214 | 200 |
c.Fatalf("Expected log %d lines, received %d\n", testLen+1, len(lines)) |
215 | 201 |
} |
216 |
- |
|
217 |
- logsCmd = exec.Command(dockerBinary, "logs", "--tail", "random", cleanedContainerID) |
|
218 |
- out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
219 |
- if err != nil { |
|
220 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
221 |
- } |
|
202 |
+ out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", cleanedContainerID) |
|
222 | 203 |
|
223 | 204 |
lines = strings.Split(out, "\n") |
224 | 205 |
|
... | ... |
@@ -228,15 +155,10 @@ func (s *DockerSuite) TestLogsTail(c *check.C) { |
228 | 228 |
} |
229 | 229 |
|
230 | 230 |
func (s *DockerSuite) TestLogsFollowStopped(c *check.C) { |
231 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello") |
|
232 |
- |
|
233 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
234 |
- if err != nil { |
|
235 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
236 |
- } |
|
231 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", "hello") |
|
237 | 232 |
|
238 | 233 |
cleanedContainerID := strings.TrimSpace(out) |
239 |
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
234 |
+ dockerCmd(c, "wait", cleanedContainerID) |
|
240 | 235 |
|
241 | 236 |
logsCmd := exec.Command(dockerBinary, "logs", "-f", cleanedContainerID) |
242 | 237 |
if err := logsCmd.Start(); err != nil { |
... | ... |
@@ -259,22 +181,13 @@ func (s *DockerSuite) TestLogsFollowStopped(c *check.C) { |
259 | 259 |
|
260 | 260 |
func (s *DockerSuite) TestLogsSince(c *check.C) { |
261 | 261 |
name := "testlogssince" |
262 |
- runCmd := exec.Command(dockerBinary, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo `date +%s` log$i; done") |
|
263 |
- out, _, err := runCommandWithOutput(runCmd) |
|
264 |
- if err != nil { |
|
265 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
266 |
- } |
|
262 |
+ out, _ := dockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo `date +%s` log$i; done") |
|
267 | 263 |
|
268 | 264 |
log2Line := strings.Split(strings.Split(out, "\n")[1], " ") |
269 | 265 |
t, err := strconv.ParseInt(log2Line[0], 10, 64) // the timestamp log2 is writen |
270 | 266 |
c.Assert(err, check.IsNil) |
271 | 267 |
since := t + 1 // add 1s so log1 & log2 doesn't show up |
272 |
- logsCmd := exec.Command(dockerBinary, "logs", "-t", fmt.Sprintf("--since=%v", since), name) |
|
273 |
- |
|
274 |
- out, _, err = runCommandWithOutput(logsCmd) |
|
275 |
- if err != nil { |
|
276 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
277 |
- } |
|
268 |
+ out, _ = dockerCmd(c, "logs", "-t", fmt.Sprintf("--since=%v", since), name) |
|
278 | 269 |
|
279 | 270 |
// Skip 2 seconds |
280 | 271 |
unexpected := []string{"log1", "log2"} |
... | ... |
@@ -283,7 +196,6 @@ func (s *DockerSuite) TestLogsSince(c *check.C) { |
283 | 283 |
c.Fatalf("unexpected log message returned=%v, since=%v\nout=%v", v, since, out) |
284 | 284 |
} |
285 | 285 |
} |
286 |
- |
|
287 | 286 |
// Test with default value specified and parameter omitted |
288 | 287 |
expected := []string{"log1", "log2", "log3"} |
289 | 288 |
for _, cmd := range []*exec.Cmd{ |
... | ... |
@@ -303,20 +215,12 @@ func (s *DockerSuite) TestLogsSince(c *check.C) { |
303 | 303 |
} |
304 | 304 |
|
305 | 305 |
func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) { |
306 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do date +%s; sleep 1; done`) |
|
307 |
- out, _, err := runCommandWithOutput(runCmd) |
|
308 |
- if err != nil { |
|
309 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
310 |
- } |
|
306 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do date +%s; sleep 1; done`) |
|
311 | 307 |
cleanedContainerID := strings.TrimSpace(out) |
312 | 308 |
|
313 | 309 |
now := daemonTime(c).Unix() |
314 | 310 |
since := now + 2 |
315 |
- logCmd := exec.Command(dockerBinary, "logs", "-f", fmt.Sprintf("--since=%v", since), cleanedContainerID) |
|
316 |
- out, _, err = runCommandWithOutput(logCmd) |
|
317 |
- if err != nil { |
|
318 |
- c.Fatalf("failed to log container: %s, %v", out, err) |
|
319 |
- } |
|
311 |
+ out, _ = dockerCmd(c, "logs", "-f", fmt.Sprintf("--since=%v", since), cleanedContainerID) |
|
320 | 312 |
lines := strings.Split(strings.TrimSpace(out), "\n") |
321 | 313 |
if len(lines) == 0 { |
322 | 314 |
c.Fatal("got no log lines") |
... | ... |
@@ -334,12 +238,7 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) { |
334 | 334 |
|
335 | 335 |
// Regression test for #8832 |
336 | 336 |
func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) { |
337 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", `usleep 200000;yes X | head -c 200000`) |
|
338 |
- |
|
339 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
340 |
- if err != nil { |
|
341 |
- c.Fatalf("run failed with errors: %s, %v", out, err) |
|
342 |
- } |
|
337 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `usleep 200000;yes X | head -c 200000`) |
|
343 | 338 |
|
344 | 339 |
cleanedContainerID := strings.TrimSpace(out) |
345 | 340 |
|
... | ... |
@@ -4,7 +4,6 @@ import ( |
4 | 4 |
"fmt" |
5 | 5 |
"io/ioutil" |
6 | 6 |
"net" |
7 |
- "os/exec" |
|
8 | 7 |
"strings" |
9 | 8 |
|
10 | 9 |
"github.com/go-check/check" |
... | ... |
@@ -44,11 +43,7 @@ func getExternalAddress(c *check.C) net.IP { |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
func getContainerLogs(c *check.C, containerID string) string { |
47 |
- runCmd := exec.Command(dockerBinary, "logs", containerID) |
|
48 |
- out, _, err := runCommandWithOutput(runCmd) |
|
49 |
- if err != nil { |
|
50 |
- c.Fatal(out, err) |
|
51 |
- } |
|
47 |
+ out, _ := dockerCmd(c, "logs", containerID) |
|
52 | 48 |
return strings.Trim(out, "\r\n") |
53 | 49 |
} |
54 | 50 |
|
... | ... |
@@ -104,12 +99,8 @@ func (s *DockerSuite) TestNetworkLoopbackNat(c *check.C) { |
104 | 104 |
msg := "it works" |
105 | 105 |
startServerContainer(c, msg, 8080) |
106 | 106 |
endpoint := getExternalAddress(c) |
107 |
- runCmd := exec.Command(dockerBinary, "run", "-t", "--net=container:server", "busybox", |
|
107 |
+ out, _ := dockerCmd(c, "run", "-t", "--net=container:server", "busybox", |
|
108 | 108 |
"sh", "-c", fmt.Sprintf("stty raw && nc -w 5 %s 8080", endpoint.String())) |
109 |
- out, _, err := runCommandWithOutput(runCmd) |
|
110 |
- if err != nil { |
|
111 |
- c.Fatal(out, err) |
|
112 |
- } |
|
113 | 109 |
final := strings.TrimRight(string(out), "\n") |
114 | 110 |
if final != msg { |
115 | 111 |
c.Fatalf("Expected message %q but received %q", msg, final) |
... | ... |
@@ -3,7 +3,6 @@ |
3 | 3 |
package main |
4 | 4 |
|
5 | 5 |
import ( |
6 |
- "os/exec" |
|
7 | 6 |
"strings" |
8 | 7 |
|
9 | 8 |
"github.com/go-check/check" |
... | ... |
@@ -22,9 +21,7 @@ func assertNwNotAvailable(c *check.C, name string) { |
22 | 22 |
} |
23 | 23 |
|
24 | 24 |
func isNwPresent(c *check.C, name string) bool { |
25 |
- runCmd := exec.Command(dockerBinary, "network", "ls") |
|
26 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
27 |
- c.Assert(err, check.IsNil) |
|
25 |
+ out, _ := dockerCmd(c, "network", "ls") |
|
28 | 26 |
lines := strings.Split(out, "\n") |
29 | 27 |
for i := 1; i < len(lines)-1; i++ { |
30 | 28 |
if strings.Contains(lines[i], name) { |
... | ... |
@@ -42,13 +39,9 @@ func (s *DockerSuite) TestDockerNetworkLsDefault(c *check.C) { |
42 | 42 |
} |
43 | 43 |
|
44 | 44 |
func (s *DockerSuite) TestDockerNetworkCreateDelete(c *check.C) { |
45 |
- runCmd := exec.Command(dockerBinary, "network", "create", "test") |
|
46 |
- _, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
47 |
- c.Assert(err, check.IsNil) |
|
45 |
+ dockerCmd(c, "network", "create", "test") |
|
48 | 46 |
assertNwIsAvailable(c, "test") |
49 | 47 |
|
50 |
- runCmd = exec.Command(dockerBinary, "network", "rm", "test") |
|
51 |
- _, _, _, err = runCommandWithStdoutStderr(runCmd) |
|
52 |
- c.Assert(err, check.IsNil) |
|
48 |
+ dockerCmd(c, "network", "rm", "test") |
|
53 | 49 |
assertNwNotAvailable(c, "test") |
54 | 50 |
} |
... | ... |
@@ -9,10 +9,7 @@ import ( |
9 | 9 |
) |
10 | 10 |
|
11 | 11 |
func (s *DockerSuite) TestCliStatsNoStream(c *check.C) { |
12 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top")) |
|
13 |
- if err != nil { |
|
14 |
- c.Fatalf("Error on container creation: %v, output: %s", err, out) |
|
15 |
- } |
|
12 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "top") |
|
16 | 13 |
id := strings.TrimSpace(out) |
17 | 14 |
if err := waitRun(id); err != nil { |
18 | 15 |
c.Fatalf("error waiting for container to start: %v", err) |
... | ... |
@@ -1,7 +1,6 @@ |
1 | 1 |
package main |
2 | 2 |
|
3 | 3 |
import ( |
4 |
- "os/exec" |
|
5 | 4 |
"strings" |
6 | 5 |
|
7 | 6 |
"github.com/docker/docker/pkg/stringutils" |
... | ... |
@@ -14,20 +13,14 @@ func (s *DockerSuite) TestTagUnprefixedRepoByName(c *check.C) { |
14 | 14 |
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") |
15 | 15 |
} |
16 | 16 |
|
17 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "testfoobarbaz") |
|
18 |
- if out, _, err := runCommandWithOutput(tagCmd); err != nil { |
|
19 |
- c.Fatal(out, err) |
|
20 |
- } |
|
17 |
+ dockerCmd(c, "tag", "busybox:latest", "testfoobarbaz") |
|
21 | 18 |
} |
22 | 19 |
|
23 | 20 |
// tagging an image by ID in a new unprefixed repo should work |
24 | 21 |
func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) { |
25 | 22 |
imageID, err := inspectField("busybox", "Id") |
26 | 23 |
c.Assert(err, check.IsNil) |
27 |
- tagCmd := exec.Command(dockerBinary, "tag", imageID, "testfoobarbaz") |
|
28 |
- if out, _, err := runCommandWithOutput(tagCmd); err != nil { |
|
29 |
- c.Fatal(out, err) |
|
30 |
- } |
|
24 |
+ dockerCmd(c, "tag", imageID, "testfoobarbaz") |
|
31 | 25 |
} |
32 | 26 |
|
33 | 27 |
// ensure we don't allow the use of invalid repository names; these tag operations should fail |
... | ... |
@@ -36,8 +29,7 @@ func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) { |
36 | 36 |
invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd"} |
37 | 37 |
|
38 | 38 |
for _, repo := range invalidRepos { |
39 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox", repo) |
|
40 |
- _, _, err := runCommandWithOutput(tagCmd) |
|
39 |
+ _, _, err := dockerCmdWithError(c, "tag", "busybox", repo) |
|
41 | 40 |
if err == nil { |
42 | 41 |
c.Fatalf("tag busybox %v should have failed", repo) |
43 | 42 |
} |
... | ... |
@@ -51,8 +43,7 @@ func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) { |
51 | 51 |
invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag} |
52 | 52 |
|
53 | 53 |
for _, repotag := range invalidTags { |
54 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox", repotag) |
|
55 |
- _, _, err := runCommandWithOutput(tagCmd) |
|
54 |
+ _, _, err := dockerCmdWithError(c, "tag", "busybox", repotag) |
|
56 | 55 |
if err == nil { |
57 | 56 |
c.Fatalf("tag busybox %v should have failed", repotag) |
58 | 57 |
} |
... | ... |
@@ -68,8 +59,7 @@ func (s *DockerSuite) TestTagValidPrefixedRepo(c *check.C) { |
68 | 68 |
validRepos := []string{"fooo/bar", "fooaa/test", "foooo:t"} |
69 | 69 |
|
70 | 70 |
for _, repo := range validRepos { |
71 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", repo) |
|
72 |
- _, _, err := runCommandWithOutput(tagCmd) |
|
71 |
+ _, _, err := dockerCmdWithError(c, "tag", "busybox:latest", repo) |
|
73 | 72 |
if err != nil { |
74 | 73 |
c.Errorf("tag busybox %v should have worked: %s", repo, err) |
75 | 74 |
continue |
... | ... |
@@ -84,12 +74,8 @@ func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) { |
84 | 84 |
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") |
85 | 85 |
} |
86 | 86 |
|
87 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test") |
|
88 |
- if out, _, err := runCommandWithOutput(tagCmd); err != nil { |
|
89 |
- c.Fatal(out, err) |
|
90 |
- } |
|
91 |
- tagCmd = exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test") |
|
92 |
- out, _, err := runCommandWithOutput(tagCmd) |
|
87 |
+ dockerCmd(c, "tag", "busybox:latest", "busybox:test") |
|
88 |
+ out, _, err := dockerCmdWithError(c, "tag", "busybox:latest", "busybox:test") |
|
93 | 89 |
if err == nil || !strings.Contains(out, "Conflict: Tag test is already set to image") { |
94 | 90 |
c.Fatal("tag busybox busybox:test should have failed,because busybox:test is existed") |
95 | 91 |
} |
... | ... |
@@ -101,14 +87,8 @@ func (s *DockerSuite) TestTagExistedNameWithForce(c *check.C) { |
101 | 101 |
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") |
102 | 102 |
} |
103 | 103 |
|
104 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test") |
|
105 |
- if out, _, err := runCommandWithOutput(tagCmd); err != nil { |
|
106 |
- c.Fatal(out, err) |
|
107 |
- } |
|
108 |
- tagCmd = exec.Command(dockerBinary, "tag", "-f", "busybox:latest", "busybox:test") |
|
109 |
- if out, _, err := runCommandWithOutput(tagCmd); err != nil { |
|
110 |
- c.Fatal(out, err) |
|
111 |
- } |
|
104 |
+ dockerCmd(c, "tag", "busybox:latest", "busybox:test") |
|
105 |
+ dockerCmd(c, "tag", "-f", "busybox:latest", "busybox:test") |
|
112 | 106 |
} |
113 | 107 |
|
114 | 108 |
func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) { |
... | ... |
@@ -116,20 +96,17 @@ func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) { |
116 | 116 |
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") |
117 | 117 |
} |
118 | 118 |
// test repository name begin with '-' |
119 |
- tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "-busybox:test") |
|
120 |
- out, _, err := runCommandWithOutput(tagCmd) |
|
119 |
+ out, _, err := dockerCmdWithError(c, "tag", "busybox:latest", "-busybox:test") |
|
121 | 120 |
if err == nil || !strings.Contains(out, "repository name component must match") { |
122 | 121 |
c.Fatal("tag a name begin with '-' should failed") |
123 | 122 |
} |
124 | 123 |
// test namespace name begin with '-' |
125 |
- tagCmd = exec.Command(dockerBinary, "tag", "busybox:latest", "-test/busybox:test") |
|
126 |
- out, _, err = runCommandWithOutput(tagCmd) |
|
124 |
+ out, _, err = dockerCmdWithError(c, "tag", "busybox:latest", "-test/busybox:test") |
|
127 | 125 |
if err == nil || !strings.Contains(out, "repository name component must match") { |
128 | 126 |
c.Fatal("tag a name begin with '-' should failed") |
129 | 127 |
} |
130 | 128 |
// test index name begin wiht '-' |
131 |
- tagCmd = exec.Command(dockerBinary, "tag", "busybox:latest", "-index:5000/busybox:test") |
|
132 |
- out, _, err = runCommandWithOutput(tagCmd) |
|
129 |
+ out, _, err = dockerCmdWithError(c, "tag", "busybox:latest", "-index:5000/busybox:test") |
|
133 | 130 |
if err == nil || !strings.Contains(out, "Invalid index name (-index:5000). Cannot begin or end with a hyphen") { |
134 | 131 |
c.Fatal("tag a name begin with '-' should failed") |
135 | 132 |
} |
... | ... |
@@ -147,16 +124,14 @@ func (s *DockerSuite) TestTagOfficialNames(c *check.C) { |
147 | 147 |
} |
148 | 148 |
|
149 | 149 |
for _, name := range names { |
150 |
- tagCmd := exec.Command(dockerBinary, "tag", "-f", "busybox:latest", name+":latest") |
|
151 |
- out, exitCode, err := runCommandWithOutput(tagCmd) |
|
150 |
+ out, exitCode, err := dockerCmdWithError(c, "tag", "-f", "busybox:latest", name+":latest") |
|
152 | 151 |
if err != nil || exitCode != 0 { |
153 | 152 |
c.Errorf("tag busybox %v should have worked: %s, %s", name, err, out) |
154 | 153 |
continue |
155 | 154 |
} |
156 | 155 |
|
157 | 156 |
// ensure we don't have multiple tag names. |
158 |
- imagesCmd := exec.Command(dockerBinary, "images") |
|
159 |
- out, _, err = runCommandWithOutput(imagesCmd) |
|
157 |
+ out, _, err = dockerCmdWithError(c, "images") |
|
160 | 158 |
if err != nil { |
161 | 159 |
c.Errorf("listing images failed with errors: %v, %s", err, out) |
162 | 160 |
} else if strings.Contains(out, name) { |
... | ... |
@@ -166,8 +141,7 @@ func (s *DockerSuite) TestTagOfficialNames(c *check.C) { |
166 | 166 |
} |
167 | 167 |
|
168 | 168 |
for _, name := range names { |
169 |
- tagCmd := exec.Command(dockerBinary, "tag", "-f", name+":latest", "fooo/bar:latest") |
|
170 |
- _, exitCode, err := runCommandWithOutput(tagCmd) |
|
169 |
+ _, exitCode, err := dockerCmdWithError(c, "tag", "-f", name+":latest", "fooo/bar:latest") |
|
171 | 170 |
if err != nil || exitCode != 0 { |
172 | 171 |
c.Errorf("tag %v fooo/bar should have worked: %s", name, err) |
173 | 172 |
continue |
... | ... |
@@ -1,27 +1,17 @@ |
1 | 1 |
package main |
2 | 2 |
|
3 | 3 |
import ( |
4 |
- "os/exec" |
|
5 | 4 |
"strings" |
6 | 5 |
|
7 | 6 |
"github.com/go-check/check" |
8 | 7 |
) |
9 | 8 |
|
10 | 9 |
func (s *DockerSuite) TestTopMultipleArgs(c *check.C) { |
11 |
- runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top") |
|
12 |
- out, _, err := runCommandWithOutput(runCmd) |
|
13 |
- if err != nil { |
|
14 |
- c.Fatalf("failed to start the container: %s, %v", out, err) |
|
15 |
- } |
|
10 |
+ out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top") |
|
16 | 11 |
|
17 | 12 |
cleanedContainerID := strings.TrimSpace(out) |
18 | 13 |
|
19 |
- topCmd := exec.Command(dockerBinary, "top", cleanedContainerID, "-o", "pid") |
|
20 |
- out, _, err = runCommandWithOutput(topCmd) |
|
21 |
- if err != nil { |
|
22 |
- c.Fatalf("failed to run top: %s, %v", out, err) |
|
23 |
- } |
|
24 |
- |
|
14 |
+ out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid") |
|
25 | 15 |
if !strings.Contains(out, "PID") { |
26 | 16 |
c.Fatalf("did not see PID after top -o pid: %s", out) |
27 | 17 |
} |
... | ... |
@@ -29,30 +19,12 @@ func (s *DockerSuite) TestTopMultipleArgs(c *check.C) { |
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
func (s *DockerSuite) TestTopNonPrivileged(c *check.C) { |
32 |
- runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top") |
|
33 |
- out, _, err := runCommandWithOutput(runCmd) |
|
34 |
- if err != nil { |
|
35 |
- c.Fatalf("failed to start the container: %s, %v", out, err) |
|
36 |
- } |
|
37 |
- |
|
32 |
+ out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top") |
|
38 | 33 |
cleanedContainerID := strings.TrimSpace(out) |
39 | 34 |
|
40 |
- topCmd := exec.Command(dockerBinary, "top", cleanedContainerID) |
|
41 |
- out1, _, err := runCommandWithOutput(topCmd) |
|
42 |
- if err != nil { |
|
43 |
- c.Fatalf("failed to run top: %s, %v", out1, err) |
|
44 |
- } |
|
45 |
- |
|
46 |
- topCmd = exec.Command(dockerBinary, "top", cleanedContainerID) |
|
47 |
- out2, _, err := runCommandWithOutput(topCmd) |
|
48 |
- if err != nil { |
|
49 |
- c.Fatalf("failed to run top: %s, %v", out2, err) |
|
50 |
- } |
|
51 |
- |
|
52 |
- killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) |
|
53 |
- if out, _, err = runCommandWithOutput(killCmd); err != nil { |
|
54 |
- c.Fatalf("failed to kill container: %s, %v", out, err) |
|
55 |
- } |
|
35 |
+ out1, _ := dockerCmd(c, "top", cleanedContainerID) |
|
36 |
+ out2, _ := dockerCmd(c, "top", cleanedContainerID) |
|
37 |
+ out, _ = dockerCmd(c, "kill", cleanedContainerID) |
|
56 | 38 |
|
57 | 39 |
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") { |
58 | 40 |
c.Fatal("top should've listed `top` in the process list, but failed twice") |
... | ... |
@@ -65,30 +37,12 @@ func (s *DockerSuite) TestTopNonPrivileged(c *check.C) { |
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
func (s *DockerSuite) TestTopPrivileged(c *check.C) { |
68 |
- runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "top") |
|
69 |
- out, _, err := runCommandWithOutput(runCmd) |
|
70 |
- if err != nil { |
|
71 |
- c.Fatalf("failed to start the container: %s, %v", out, err) |
|
72 |
- } |
|
73 |
- |
|
68 |
+ out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top") |
|
74 | 69 |
cleanedContainerID := strings.TrimSpace(out) |
75 | 70 |
|
76 |
- topCmd := exec.Command(dockerBinary, "top", cleanedContainerID) |
|
77 |
- out1, _, err := runCommandWithOutput(topCmd) |
|
78 |
- if err != nil { |
|
79 |
- c.Fatalf("failed to run top: %s, %v", out1, err) |
|
80 |
- } |
|
81 |
- |
|
82 |
- topCmd = exec.Command(dockerBinary, "top", cleanedContainerID) |
|
83 |
- out2, _, err := runCommandWithOutput(topCmd) |
|
84 |
- if err != nil { |
|
85 |
- c.Fatalf("failed to run top: %s, %v", out2, err) |
|
86 |
- } |
|
87 |
- |
|
88 |
- killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) |
|
89 |
- if out, _, err = runCommandWithOutput(killCmd); err != nil { |
|
90 |
- c.Fatalf("failed to kill container: %s, %v", out, err) |
|
91 |
- } |
|
71 |
+ out1, _ := dockerCmd(c, "top", cleanedContainerID) |
|
72 |
+ out2, _ := dockerCmd(c, "top", cleanedContainerID) |
|
73 |
+ out, _ = dockerCmd(c, "kill", cleanedContainerID) |
|
92 | 74 |
|
93 | 75 |
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") { |
94 | 76 |
c.Fatal("top should've listed `top` in the process list, but failed twice") |
... | ... |
@@ -1,7 +1,6 @@ |
1 | 1 |
package main |
2 | 2 |
|
3 | 3 |
import ( |
4 |
- "os/exec" |
|
5 | 4 |
"strings" |
6 | 5 |
|
7 | 6 |
"github.com/go-check/check" |
... | ... |
@@ -9,12 +8,7 @@ import ( |
9 | 9 |
|
10 | 10 |
// ensure docker version works |
11 | 11 |
func (s *DockerSuite) TestVersionEnsureSucceeds(c *check.C) { |
12 |
- versionCmd := exec.Command(dockerBinary, "version") |
|
13 |
- out, _, err := runCommandWithOutput(versionCmd) |
|
14 |
- if err != nil { |
|
15 |
- c.Fatalf("failed to execute docker version: %s, %v", out, err) |
|
16 |
- } |
|
17 |
- |
|
12 |
+ out, _ := dockerCmd(c, "version") |
|
18 | 13 |
stringsToCheck := map[string]int{ |
19 | 14 |
"Client:": 1, |
20 | 15 |
"Server:": 1, |
... | ... |
@@ -11,15 +11,11 @@ import ( |
11 | 11 |
|
12 | 12 |
// non-blocking wait with 0 exit code |
13 | 13 |
func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) { |
14 |
- |
|
15 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "true") |
|
16 |
- out, _, err := runCommandWithOutput(runCmd) |
|
17 |
- if err != nil { |
|
18 |
- c.Fatal(out, err) |
|
19 |
- } |
|
14 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "true") |
|
20 | 15 |
containerID := strings.TrimSpace(out) |
21 | 16 |
|
22 | 17 |
status := "true" |
18 |
+ var err error |
|
23 | 19 |
for i := 0; status != "false"; i++ { |
24 | 20 |
status, err = inspectField(containerID, "State.Running") |
25 | 21 |
c.Assert(err, check.IsNil) |
... | ... |
@@ -30,11 +26,9 @@ func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) { |
30 | 30 |
} |
31 | 31 |
} |
32 | 32 |
|
33 |
- runCmd = exec.Command(dockerBinary, "wait", containerID) |
|
34 |
- out, _, err = runCommandWithOutput(runCmd) |
|
35 |
- |
|
36 |
- if err != nil || strings.TrimSpace(out) != "0" { |
|
37 |
- c.Fatal("failed to set up container", out, err) |
|
33 |
+ out, _ = dockerCmd(c, "wait", containerID) |
|
34 |
+ if strings.TrimSpace(out) != "0" { |
|
35 |
+ c.Fatal("failed to set up container", out) |
|
38 | 36 |
} |
39 | 37 |
|
40 | 38 |
} |
... | ... |
@@ -70,15 +64,11 @@ func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) { |
70 | 70 |
|
71 | 71 |
// non-blocking wait with random exit code |
72 | 72 |
func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) { |
73 |
- |
|
74 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "exit 99") |
|
75 |
- out, _, err := runCommandWithOutput(runCmd) |
|
76 |
- if err != nil { |
|
77 |
- c.Fatal(out, err) |
|
78 |
- } |
|
73 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "exit 99") |
|
79 | 74 |
containerID := strings.TrimSpace(out) |
80 | 75 |
|
81 | 76 |
status := "true" |
77 |
+ var err error |
|
82 | 78 |
for i := 0; status != "false"; i++ { |
83 | 79 |
status, err = inspectField(containerID, "State.Running") |
84 | 80 |
c.Assert(err, check.IsNil) |
... | ... |
@@ -89,11 +79,9 @@ func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) { |
89 | 89 |
} |
90 | 90 |
} |
91 | 91 |
|
92 |
- runCmd = exec.Command(dockerBinary, "wait", containerID) |
|
93 |
- out, _, err = runCommandWithOutput(runCmd) |
|
94 |
- |
|
95 |
- if err != nil || strings.TrimSpace(out) != "99" { |
|
96 |
- c.Fatal("failed to set up container", out, err) |
|
92 |
+ out, _ = dockerCmd(c, "wait", containerID) |
|
93 |
+ if strings.TrimSpace(out) != "99" { |
|
94 |
+ c.Fatal("failed to set up container", out) |
|
97 | 95 |
} |
98 | 96 |
|
99 | 97 |
} |