Browse code

CI: use dockerCmd in integration-cli when possible

Signed-off-by: Hu Keping <hukeping@huawei.com>

Hu Keping authored on 2015/07/22 03:01:24
Showing 6 changed files
... ...
@@ -22,7 +22,7 @@ func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) {
22 22
 
23 23
 	out, _ = dockerCmd(c, "logs", cleanedContainerID)
24 24
 	if out != "foobar\nfoobar\n" {
25
-		c.Errorf("container should've printed 'foobar' twice")
25
+		c.Errorf("container should've printed 'foobar' twice, got %v", out)
26 26
 	}
27 27
 }
28 28
 
... ...
@@ -16,25 +16,12 @@ import (
16 16
 // save a repo using gz compression and try to load it using stdout
17 17
 func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
18 18
 	name := "test-save-xz-and-load-repo-stdout"
19
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
20
-	out, _, err := runCommandWithOutput(runCmd)
21
-	if err != nil {
22
-		c.Fatalf("failed to create a container: %v %v", out, err)
23
-	}
19
+	dockerCmd(c, "run", "--name", name, "busybox", "true")
24 20
 
25 21
 	repoName := "foobar-save-load-test-xz-gz"
22
+	out, _ := dockerCmd(c, "commit", name, repoName)
26 23
 
27
-	commitCmd := exec.Command(dockerBinary, "commit", name, repoName)
28
-	out, _, err = runCommandWithOutput(commitCmd)
29
-	if err != nil {
30
-		c.Fatalf("failed to commit container: %v %v", out, err)
31
-	}
32
-
33
-	inspectCmd := exec.Command(dockerBinary, "inspect", repoName)
34
-	before, _, err := runCommandWithOutput(inspectCmd)
35
-	if err != nil {
36
-		c.Fatalf("the repo should exist before saving it: %v %v", before, err)
37
-	}
24
+	dockerCmd(c, "inspect", repoName)
38 25
 
39 26
 	repoTarball, _, err := runCommandPipelineWithOutput(
40 27
 		exec.Command(dockerBinary, "save", repoName),
... ...
@@ -52,8 +39,7 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
52 52
 		c.Fatalf("expected error, but succeeded with no error and output: %v", out)
53 53
 	}
54 54
 
55
-	inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
56
-	after, _, err := runCommandWithOutput(inspectCmd)
55
+	after, _, err := dockerCmdWithError(c, "inspect", repoName)
57 56
 	if err == nil {
58 57
 		c.Fatalf("the repo should not exist: %v", after)
59 58
 	}
... ...
@@ -62,27 +48,14 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
62 62
 // save a repo using xz+gz compression and try to load it using stdout
63 63
 func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
64 64
 	name := "test-save-xz-gz-and-load-repo-stdout"
65
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
66
-	out, _, err := runCommandWithOutput(runCmd)
67
-	if err != nil {
68
-		c.Fatalf("failed to create a container: %v %v", out, err)
69
-	}
65
+	dockerCmd(c, "run", "--name", name, "busybox", "true")
70 66
 
71 67
 	repoName := "foobar-save-load-test-xz-gz"
68
+	dockerCmd(c, "commit", name, repoName)
72 69
 
73
-	commitCmd := exec.Command(dockerBinary, "commit", name, repoName)
74
-	out, _, err = runCommandWithOutput(commitCmd)
75
-	if err != nil {
76
-		c.Fatalf("failed to commit container: %v %v", out, err)
77
-	}
78
-
79
-	inspectCmd := exec.Command(dockerBinary, "inspect", repoName)
80
-	before, _, err := runCommandWithOutput(inspectCmd)
81
-	if err != nil {
82
-		c.Fatalf("the repo should exist before saving it: %v %v", before, err)
83
-	}
70
+	dockerCmd(c, "inspect", repoName)
84 71
 
85
-	out, _, err = runCommandPipelineWithOutput(
72
+	out, _, err := runCommandPipelineWithOutput(
86 73
 		exec.Command(dockerBinary, "save", repoName),
87 74
 		exec.Command("xz", "-c"),
88 75
 		exec.Command("gzip", "-c"))
... ...
@@ -99,8 +72,7 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
99 99
 		c.Fatalf("expected error, but succeeded with no error and output: %v", out)
100 100
 	}
101 101
 
102
-	inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
103
-	after, _, err := runCommandWithOutput(inspectCmd)
102
+	after, _, err := dockerCmdWithError(c, "inspect", repoName)
104 103
 	if err == nil {
105 104
 		c.Fatalf("the repo should not exist: %v", after)
106 105
 	}
... ...
@@ -108,55 +80,34 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
108 108
 
109 109
 func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
110 110
 	repoName := "foobar-save-single-tag-test"
111
+	dockerCmd(c, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
111 112
 
112
-	tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
113
-	if out, _, err := runCommandWithOutput(tagCmd); err != nil {
114
-		c.Fatalf("failed to tag repo: %s, %v", out, err)
115
-	}
116
-
117
-	idCmd := exec.Command(dockerBinary, "images", "-q", "--no-trunc", repoName)
118
-	out, _, err := runCommandWithOutput(idCmd)
119
-	if err != nil {
120
-		c.Fatalf("failed to get repo ID: %s, %v", out, err)
121
-	}
113
+	out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName)
122 114
 	cleanedImageID := strings.TrimSpace(out)
123 115
 
124
-	out, _, err = runCommandPipelineWithOutput(
116
+	out, _, err := runCommandPipelineWithOutput(
125 117
 		exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
126 118
 		exec.Command("tar", "t"),
127 119
 		exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
128 120
 	if err != nil {
129 121
 		c.Fatalf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
130 122
 	}
131
-
132 123
 }
133 124
 
134 125
 func (s *DockerSuite) TestSaveImageId(c *check.C) {
135 126
 	repoName := "foobar-save-image-id-test"
127
+	dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
136 128
 
137
-	tagCmd := exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
138
-	if out, _, err := runCommandWithOutput(tagCmd); err != nil {
139
-		c.Fatalf("failed to tag repo: %s, %v", out, err)
140
-	}
141
-
142
-	idLongCmd := exec.Command(dockerBinary, "images", "-q", "--no-trunc", repoName)
143
-	out, _, err := runCommandWithOutput(idLongCmd)
144
-	if err != nil {
145
-		c.Fatalf("failed to get repo ID: %s, %v", out, err)
146
-	}
147
-
129
+	out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName)
148 130
 	cleanedLongImageID := strings.TrimSpace(out)
149 131
 
150
-	idShortCmd := exec.Command(dockerBinary, "images", "-q", repoName)
151
-	out, _, err = runCommandWithOutput(idShortCmd)
152
-	if err != nil {
153
-		c.Fatalf("failed to get repo short ID: %s, %v", out, err)
154
-	}
155
-
132
+	out, _ = dockerCmd(c, "images", "-q", repoName)
156 133
 	cleanedShortImageID := strings.TrimSpace(out)
157 134
 
158 135
 	saveCmd := exec.Command(dockerBinary, "save", cleanedShortImageID)
159 136
 	tarCmd := exec.Command("tar", "t")
137
+
138
+	var err error
160 139
 	tarCmd.Stdin, err = saveCmd.StdoutPipe()
161 140
 	if err != nil {
162 141
 		c.Fatalf("cannot set stdout pipe for tar: %v", err)
... ...
@@ -181,45 +132,28 @@ func (s *DockerSuite) TestSaveImageId(c *check.C) {
181 181
 	if err != nil {
182 182
 		c.Fatalf("failed to save repo with image ID: %s, %v", out, err)
183 183
 	}
184
-
185 184
 }
186 185
 
187 186
 // save a repo and try to load it using flags
188 187
 func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
189 188
 	name := "test-save-and-load-repo-flags"
190
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
191
-	out, _, err := runCommandWithOutput(runCmd)
192
-	if err != nil {
193
-		c.Fatalf("failed to create a container: %s, %v", out, err)
194
-	}
189
+	dockerCmd(c, "run", "--name", name, "busybox", "true")
190
+
195 191
 	repoName := "foobar-save-load-test"
196 192
 
197
-	commitCmd := exec.Command(dockerBinary, "commit", name, repoName)
198 193
 	deleteImages(repoName)
199
-	if out, _, err = runCommandWithOutput(commitCmd); err != nil {
200
-		c.Fatalf("failed to commit container: %s, %v", out, err)
201
-	}
202
-
203
-	inspectCmd := exec.Command(dockerBinary, "inspect", repoName)
204
-	before, _, err := runCommandWithOutput(inspectCmd)
205
-	if err != nil {
206
-		c.Fatalf("the repo should exist before saving it: %s, %v", before, err)
194
+	dockerCmd(c, "commit", name, repoName)
207 195
 
208
-	}
196
+	before, _ := dockerCmd(c, "inspect", repoName)
209 197
 
210
-	out, _, err = runCommandPipelineWithOutput(
198
+	out, _, err := runCommandPipelineWithOutput(
211 199
 		exec.Command(dockerBinary, "save", repoName),
212 200
 		exec.Command(dockerBinary, "load"))
213 201
 	if err != nil {
214 202
 		c.Fatalf("failed to save and load repo: %s, %v", out, err)
215 203
 	}
216 204
 
217
-	inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
218
-	after, _, err := runCommandWithOutput(inspectCmd)
219
-	if err != nil {
220
-		c.Fatalf("the repo should exist after loading it: %s, %v", after, err)
221
-	}
222
-
205
+	after, _ := dockerCmd(c, "inspect", repoName)
223 206
 	if before != after {
224 207
 		c.Fatalf("inspect is not the same after a save / load")
225 208
 	}
... ...
@@ -229,19 +163,12 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
229 229
 	repoName := "foobar-save-multi-name-test"
230 230
 
231 231
 	// Make one image
232
-	tagCmd := exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v-one:latest", repoName))
233
-	if out, _, err := runCommandWithOutput(tagCmd); err != nil {
234
-		c.Fatalf("failed to tag repo: %s, %v", out, err)
235
-	}
232
+	dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-one:latest", repoName))
236 233
 
237 234
 	// Make two images
238
-	tagCmd = exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
239
-	out, _, err := runCommandWithOutput(tagCmd)
240
-	if err != nil {
241
-		c.Fatalf("failed to tag repo: %s, %v", out, err)
242
-	}
235
+	dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
243 236
 
244
-	out, _, err = runCommandPipelineWithOutput(
237
+	out, _, err := runCommandPipelineWithOutput(
245 238
 		exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)),
246 239
 		exec.Command("tar", "xO", "repositories"),
247 240
 		exec.Command("grep", "-q", "-E", "(-one|-two)"),
... ...
@@ -249,26 +176,18 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
249 249
 	if err != nil {
250 250
 		c.Fatalf("failed to save multiple repos: %s, %v", out, err)
251 251
 	}
252
-
253 252
 }
254 253
 
255 254
 func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
256 255
 
257 256
 	makeImage := func(from string, tag string) string {
258
-		runCmd := exec.Command(dockerBinary, "run", "-d", from, "true")
259 257
 		var (
260 258
 			out string
261
-			err error
262 259
 		)
263
-		if out, _, err = runCommandWithOutput(runCmd); err != nil {
264
-			c.Fatalf("failed to create a container: %v %v", out, err)
265
-		}
260
+		out, _ = dockerCmd(c, "run", "-d", from, "true")
266 261
 		cleanedContainerID := strings.TrimSpace(out)
267 262
 
268
-		commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, tag)
269
-		if out, _, err = runCommandWithOutput(commitCmd); err != nil {
270
-			c.Fatalf("failed to commit container: %v %v", out, err)
271
-		}
263
+		out, _ = dockerCmd(c, "commit", cleanedContainerID, tag)
272 264
 		imageID := strings.TrimSpace(out)
273 265
 		return imageID
274 266
 	}
... ...
@@ -294,11 +213,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
294 294
 	actual := strings.Split(strings.TrimSpace(out), "\n")
295 295
 
296 296
 	// make the list of expected layers
297
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "history", "-q", "--no-trunc", "busybox:latest"))
298
-	if err != nil {
299
-		c.Fatalf("failed to get history: %s, %v", out, err)
300
-	}
301
-
297
+	out, _ = dockerCmd(c, "history", "-q", "--no-trunc", "busybox:latest")
302 298
 	expected := append(strings.Split(strings.TrimSpace(out), "\n"), idFoo, idBar)
303 299
 
304 300
 	sort.Strings(actual)
... ...
@@ -306,7 +221,6 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
306 306
 	if !reflect.DeepEqual(expected, actual) {
307 307
 		c.Fatalf("archive does not contains the right layers: got %v, expected %v", actual, expected)
308 308
 	}
309
-
310 309
 }
311 310
 
312 311
 // Issue #6722 #5892 ensure directories are included in changes
... ...
@@ -15,24 +15,12 @@ import (
15 15
 // save a repo and try to load it using stdout
16 16
 func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
17 17
 	name := "test-save-and-load-repo-stdout"
18
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
19
-	out, _, err := runCommandWithOutput(runCmd)
20
-	if err != nil {
21
-		c.Fatalf("failed to create a container: %s, %v", out, err)
22
-	}
18
+	dockerCmd(c, "run", "--name", name, "busybox", "true")
23 19
 
24 20
 	repoName := "foobar-save-load-test"
21
+	out, _ := dockerCmd(c, "commit", name, repoName)
25 22
 
26
-	commitCmd := exec.Command(dockerBinary, "commit", name, repoName)
27
-	if out, _, err = runCommandWithOutput(commitCmd); err != nil {
28
-		c.Fatalf("failed to commit container: %s, %v", out, err)
29
-	}
30
-
31
-	inspectCmd := exec.Command(dockerBinary, "inspect", repoName)
32
-	before, _, err := runCommandWithOutput(inspectCmd)
33
-	if err != nil {
34
-		c.Fatalf("the repo should exist before saving it: %s, %v", before, err)
35
-	}
23
+	before, _ := dockerCmd(c, "inspect", repoName)
36 24
 
37 25
 	tmpFile, err := ioutil.TempFile("", "foobar-save-load-test.tar")
38 26
 	c.Assert(err, check.IsNil)
... ...
@@ -57,11 +45,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
57 57
 		c.Fatalf("failed to load repo: %s, %v", out, err)
58 58
 	}
59 59
 
60
-	inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
61
-	after, _, err := runCommandWithOutput(inspectCmd)
62
-	if err != nil {
63
-		c.Fatalf("the repo should exist after loading it: %s %v", after, err)
64
-	}
60
+	after, _ := dockerCmd(c, "inspect", repoName)
65 61
 
66 62
 	if before != after {
67 63
 		c.Fatalf("inspect is not the same after a save / load")
... ...
@@ -94,5 +78,4 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
94 94
 	if !bytes.Contains(buf[:n], []byte("Cowardly refusing")) {
95 95
 		c.Fatal("help output is not being yielded", out)
96 96
 	}
97
-
98 97
 }
... ...
@@ -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"
... ...
@@ -10,21 +9,19 @@ import (
10 10
 // search for repos named  "registry" on the central registry
11 11
 func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
12 12
 	testRequires(c, Network)
13
-	searchCmd := exec.Command(dockerBinary, "search", "busybox")
14
-	out, exitCode, err := runCommandWithOutput(searchCmd)
15
-	if err != nil || exitCode != 0 {
16
-		c.Fatalf("failed to search on the central registry: %s, %v", out, err)
13
+
14
+	out, exitCode := dockerCmd(c, "search", "busybox")
15
+	if exitCode != 0 {
16
+		c.Fatalf("failed to search on the central registry: %s", out)
17 17
 	}
18 18
 
19 19
 	if !strings.Contains(out, "Busybox base image.") {
20 20
 		c.Fatal("couldn't find any repository named (or containing) 'Busybox base image.'")
21 21
 	}
22
-
23 22
 }
24 23
 
25 24
 func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
26
-	searchCmdStarsChars := exec.Command(dockerBinary, "search", "--stars=a", "busybox")
27
-	out, exitCode, err := runCommandWithOutput(searchCmdStarsChars)
25
+	out, exitCode, err := dockerCmdWithError(c, "search", "--stars=a", "busybox")
28 26
 	if err == nil || exitCode == 0 {
29 27
 		c.Fatalf("Should not get right information: %s, %v", out, err)
30 28
 	}
... ...
@@ -33,8 +30,7 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
33 33
 		c.Fatal("couldn't find the invalid value warning")
34 34
 	}
35 35
 
36
-	searchCmdStarsNegativeNumber := exec.Command(dockerBinary, "search", "-s=-1", "busybox")
37
-	out, exitCode, err = runCommandWithOutput(searchCmdStarsNegativeNumber)
36
+	out, exitCode, err = dockerCmdWithError(c, "search", "-s=-1", "busybox")
38 37
 	if err == nil || exitCode == 0 {
39 38
 		c.Fatalf("Should not get right information: %s, %v", out, err)
40 39
 	}
... ...
@@ -42,64 +38,54 @@ func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
42 42
 	if !strings.Contains(out, "invalid value") {
43 43
 		c.Fatal("couldn't find the invalid value warning")
44 44
 	}
45
-
46 45
 }
47 46
 
48 47
 func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
49 48
 	testRequires(c, Network)
50
-	searchCmdhelp := exec.Command(dockerBinary, "search", "--help")
51
-	out, exitCode, err := runCommandWithOutput(searchCmdhelp)
52
-	if err != nil || exitCode != 0 {
53
-		c.Fatalf("failed to get search help information: %s, %v", out, err)
49
+
50
+	out, exitCode := dockerCmd(c, "search", "--help")
51
+	if exitCode != 0 {
52
+		c.Fatalf("failed to get search help information: %s", out)
54 53
 	}
55 54
 
56 55
 	if !strings.Contains(out, "Usage:\tdocker search [OPTIONS] TERM") {
57
-		c.Fatalf("failed to show docker search usage: %s, %v", out, err)
56
+		c.Fatalf("failed to show docker search usage: %s", out)
58 57
 	}
59 58
 
60
-	searchCmd := exec.Command(dockerBinary, "search", "busybox")
61
-	outSearchCmd, exitCode, err := runCommandWithOutput(searchCmd)
62
-	if err != nil || exitCode != 0 {
63
-		c.Fatalf("failed to search on the central registry: %s, %v", outSearchCmd, err)
59
+	outSearchCmd, exitCode := dockerCmd(c, "search", "busybox")
60
+	if exitCode != 0 {
61
+		c.Fatalf("failed to search on the central registry: %s", outSearchCmd)
64 62
 	}
65 63
 
66
-	searchCmdNotrunc := exec.Command(dockerBinary, "search", "--no-trunc=true", "busybox")
67
-	outSearchCmdNotrunc, _, err := runCommandWithOutput(searchCmdNotrunc)
68
-	if err != nil {
69
-		c.Fatalf("failed to search on the central registry: %s, %v", outSearchCmdNotrunc, err)
70
-	}
64
+	outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox")
71 65
 
72 66
 	if len(outSearchCmd) > len(outSearchCmdNotrunc) {
73 67
 		c.Fatalf("The no-trunc option can't take effect.")
74 68
 	}
75 69
 
76
-	searchCmdautomated := exec.Command(dockerBinary, "search", "--automated=true", "busybox")
77
-	outSearchCmdautomated, exitCode, err := runCommandWithOutput(searchCmdautomated) //The busybox is a busybox base image, not an AUTOMATED image.
78
-	if err != nil || exitCode != 0 {
79
-		c.Fatalf("failed to search with automated=true on the central registry: %s, %v", outSearchCmdautomated, err)
70
+	outSearchCmdautomated, exitCode := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
71
+	if exitCode != 0 {
72
+		c.Fatalf("failed to search with automated=true on the central registry: %s", outSearchCmdautomated)
80 73
 	}
81 74
 
82 75
 	outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
83 76
 	for i := range outSearchCmdautomatedSlice {
84 77
 		if strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox ") {
85
-			c.Fatalf("The busybox is not an AUTOMATED image: %s, %v", out, err)
78
+			c.Fatalf("The busybox is not an AUTOMATED image: %s", out)
86 79
 		}
87 80
 	}
88 81
 
89
-	searchCmdStars := exec.Command(dockerBinary, "search", "-s=2", "busybox")
90
-	outSearchCmdStars, exitCode, err := runCommandWithOutput(searchCmdStars)
91
-	if err != nil || exitCode != 0 {
92
-		c.Fatalf("failed to search with stars=2 on the central registry: %s, %v", outSearchCmdStars, err)
82
+	outSearchCmdStars, exitCode := dockerCmd(c, "search", "-s=2", "busybox")
83
+	if exitCode != 0 {
84
+		c.Fatalf("failed to search with stars=2 on the central registry: %s", outSearchCmdStars)
93 85
 	}
94 86
 
95 87
 	if strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]") {
96
-		c.Fatalf("The quantity of images with stars should be less than that of all images: %s, %v", outSearchCmdStars, err)
88
+		c.Fatalf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars)
97 89
 	}
98 90
 
99
-	searchCmdOptions := exec.Command(dockerBinary, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
100
-	out, exitCode, err = runCommandWithOutput(searchCmdOptions)
101
-	if err != nil || exitCode != 0 {
102
-		c.Fatalf("failed to search with stars&automated&no-trunc options on the central registry: %s, %v", out, err)
91
+	out, exitCode = dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
92
+	if exitCode != 0 {
93
+		c.Fatalf("failed to search with stars&automated&no-trunc options on the central registry: %s", out)
103 94
 	}
104
-
105 95
 }
... ...
@@ -4,7 +4,6 @@ package main
4 4
 
5 5
 import (
6 6
 	"fmt"
7
-	"os/exec"
8 7
 	"strings"
9 8
 
10 9
 	"github.com/go-check/check"
... ...
@@ -23,9 +22,7 @@ func assertSrvNotAvailable(c *check.C, sname, name string) {
23 23
 }
24 24
 
25 25
 func isSrvPresent(c *check.C, sname, name string) bool {
26
-	runCmd := exec.Command(dockerBinary, "service", "ls")
27
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
28
-	c.Assert(err, check.IsNil)
26
+	out, _, _ := dockerCmdWithStdoutStderr(c, "service", "ls")
29 27
 	lines := strings.Split(out, "\n")
30 28
 	for i := 1; i < len(lines)-1; i++ {
31 29
 		if strings.Contains(lines[i], sname) && strings.Contains(lines[i], name) {
... ...
@@ -36,9 +33,7 @@ func isSrvPresent(c *check.C, sname, name string) bool {
36 36
 }
37 37
 
38 38
 func isCntPresent(c *check.C, cname, sname, name string) bool {
39
-	runCmd := exec.Command(dockerBinary, "service", "ls", "--no-trunc")
40
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
41
-	c.Assert(err, check.IsNil)
39
+	out, _, _ := dockerCmdWithStdoutStderr(c, "service", "ls", "--no-trunc")
42 40
 	lines := strings.Split(out, "\n")
43 41
 	for i := 1; i < len(lines)-1; i++ {
44 42
 		fmt.Println(lines)
... ...
@@ -50,37 +45,25 @@ func isCntPresent(c *check.C, cname, sname, name string) bool {
50 50
 }
51 51
 
52 52
 func (s *DockerSuite) TestDockerServiceCreateDelete(c *check.C) {
53
-	runCmd := exec.Command(dockerBinary, "network", "create", "test")
54
-	_, _, _, err := runCommandWithStdoutStderr(runCmd)
55
-	c.Assert(err, check.IsNil)
53
+	dockerCmdWithStdoutStderr(c, "network", "create", "test")
56 54
 	assertNwIsAvailable(c, "test")
57 55
 
58
-	runCmd = exec.Command(dockerBinary, "service", "publish", "s1.test")
59
-	_, _, _, err = runCommandWithStdoutStderr(runCmd)
60
-	c.Assert(err, check.IsNil)
56
+	dockerCmdWithStdoutStderr(c, "service", "publish", "s1.test")
61 57
 	assertSrvIsAvailable(c, "s1", "test")
62 58
 
63
-	runCmd = exec.Command(dockerBinary, "service", "unpublish", "s1.test")
64
-	_, _, _, err = runCommandWithStdoutStderr(runCmd)
65
-	c.Assert(err, check.IsNil)
59
+	dockerCmdWithStdoutStderr(c, "service", "unpublish", "s1.test")
66 60
 	assertSrvNotAvailable(c, "s1", "test")
67 61
 
68
-	runCmd = exec.Command(dockerBinary, "network", "rm", "test")
69
-	_, _, _, err = runCommandWithStdoutStderr(runCmd)
70
-	c.Assert(err, check.IsNil)
62
+	dockerCmdWithStdoutStderr(c, "network", "rm", "test")
71 63
 	assertNwNotAvailable(c, "test")
72 64
 }
73 65
 
74 66
 func (s *DockerSuite) TestDockerPublishServiceFlag(c *check.C) {
75 67
 	// Run saying the container is the backend for the specified service on the specified network
76
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--expose=23", "--publish-service", "telnet.production", "busybox", "top")
77
-	out, _, err := runCommandWithOutput(runCmd)
78
-	c.Assert(err, check.IsNil)
68
+	out, _ := dockerCmd(c, "run", "-d", "--expose=23", "--publish-service", "telnet.production", "busybox", "top")
79 69
 	cid := strings.TrimSpace(out)
80 70
 
81 71
 	// Verify container is attached in service ps o/p
82 72
 	assertSrvIsAvailable(c, "telnet", "production")
83
-	runCmd = exec.Command(dockerBinary, "rm", "-f", cid)
84
-	out, _, err = runCommandWithOutput(runCmd)
85
-	c.Assert(err, check.IsNil)
73
+	dockerCmd(c, "rm", "-f", cid)
86 74
 }
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"strings"
7 6
 	"time"
8 7
 
... ...
@@ -11,12 +10,11 @@ import (
11 11
 
12 12
 // Regression test for https://github.com/docker/docker/issues/7843
13 13
 func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
14
-
15 14
 	dockerCmd(c, "run", "-d", "--name", "test", "busybox")
16 15
 	dockerCmd(c, "wait", "test")
17 16
 
18 17
 	// Expect this to fail because the above container is stopped, this is what we want
19
-	if _, err := runCommand(exec.Command(dockerBinary, "run", "-d", "--name", "test2", "--link", "test:test", "busybox")); err == nil {
18
+	if _, _, err := dockerCmdWithError(c, "run", "-d", "--name", "test2", "--link", "test:test", "busybox"); err == nil {
20 19
 		c.Fatal("Expected error but got none")
21 20
 	}
22 21
 
... ...
@@ -24,7 +22,7 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
24 24
 	go func() {
25 25
 		// Attempt to start attached to the container that won't start
26 26
 		// This should return an error immediately since the container can't be started
27
-		if _, err := runCommand(exec.Command(dockerBinary, "start", "-a", "test2")); err == nil {
27
+		if _, _, err := dockerCmdWithError(c, "start", "-a", "test2"); err == nil {
28 28
 			ch <- fmt.Errorf("Expected error but got none")
29 29
 		}
30 30
 		close(ch)
... ...
@@ -36,28 +34,17 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
36 36
 	case <-time.After(time.Second):
37 37
 		c.Fatalf("Attach did not exit properly")
38 38
 	}
39
-
40 39
 }
41 40
 
42 41
 // gh#8555: Exit code should be passed through when using start -a
43 42
 func (s *DockerSuite) TestStartAttachCorrectExitCode(c *check.C) {
44
-
45
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1")
46
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
47
-	if err != nil {
48
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
49
-	}
50
-
43
+	out, _, _ := dockerCmdWithStdoutStderr(c, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1")
51 44
 	out = strings.TrimSpace(out)
52 45
 
53 46
 	// make sure the container has exited before trying the "start -a"
54
-	waitCmd := exec.Command(dockerBinary, "wait", out)
55
-	if _, _, err = runCommandWithOutput(waitCmd); err != nil {
56
-		c.Fatalf("Failed to wait on container: %v", err)
57
-	}
47
+	dockerCmd(c, "wait", out)
58 48
 
59
-	startCmd := exec.Command(dockerBinary, "start", "-a", out)
60
-	startOut, exitCode, err := runCommandWithOutput(startCmd)
49
+	startOut, exitCode, err := dockerCmdWithError(c, "start", "-a", out)
61 50
 	if err != nil && !strings.Contains("exit status 1", fmt.Sprintf("%s", err)) {
62 51
 		c.Fatalf("start command failed unexpectedly with error: %v, output: %q", err, startOut)
63 52
 	}
... ...
@@ -68,29 +55,16 @@ func (s *DockerSuite) TestStartAttachCorrectExitCode(c *check.C) {
68 68
 }
69 69
 
70 70
 func (s *DockerSuite) TestStartAttachSilent(c *check.C) {
71
-
72 71
 	name := "teststartattachcorrectexitcode"
73
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "echo", "test")
74
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
75
-	if err != nil {
76
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
77
-	}
72
+	dockerCmd(c, "run", "--name", name, "busybox", "echo", "test")
78 73
 
79 74
 	// make sure the container has exited before trying the "start -a"
80
-	waitCmd := exec.Command(dockerBinary, "wait", name)
81
-	if _, _, err = runCommandWithOutput(waitCmd); err != nil {
82
-		c.Fatalf("wait command failed with error: %v", err)
83
-	}
75
+	dockerCmd(c, "wait", name)
84 76
 
85
-	startCmd := exec.Command(dockerBinary, "start", "-a", name)
86
-	startOut, _, err := runCommandWithOutput(startCmd)
87
-	if err != nil {
88
-		c.Fatalf("start command failed unexpectedly with error: %v, output: %q", err, startOut)
89
-	}
77
+	startOut, _ := dockerCmd(c, "start", "-a", name)
90 78
 	if expected := "test\n"; startOut != expected {
91 79
 		c.Fatalf("start -a produced unexpected output: expected %q, got %q", expected, startOut)
92 80
 	}
93
-
94 81
 }
95 82
 
96 83
 func (s *DockerSuite) TestStartRecordError(c *check.C) {
... ...
@@ -104,10 +78,11 @@ func (s *DockerSuite) TestStartRecordError(c *check.C) {
104 104
 	}
105 105
 
106 106
 	// Expect this to fail and records error because of ports conflict
107
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "test2", "-p", "9999:9999", "busybox", "top"))
107
+	out, _, err := dockerCmdWithError(c, "run", "-d", "--name", "test2", "-p", "9999:9999", "busybox", "top")
108 108
 	if err == nil {
109 109
 		c.Fatalf("Expected error but got none, output %q", out)
110 110
 	}
111
+
111 112
 	stateErr, err = inspectField("test2", "State.Error")
112 113
 	c.Assert(err, check.IsNil)
113 114
 	expected := "port is already allocated"
... ...
@@ -123,47 +98,31 @@ func (s *DockerSuite) TestStartRecordError(c *check.C) {
123 123
 	if stateErr != "" {
124 124
 		c.Fatalf("Expected to not have state error but got state.Error(%q)", stateErr)
125 125
 	}
126
-
127 126
 }
128 127
 
129 128
 func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
130 129
 	defer unpauseAllContainers()
131 130
 
132
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
133
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
134
-		c.Fatal(out, err)
135
-	}
131
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
136 132
 
137
-	runCmd = exec.Command(dockerBinary, "pause", "testing")
138
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
139
-		c.Fatal(out, err)
140
-	}
133
+	dockerCmd(c, "pause", "testing")
141 134
 
142
-	runCmd = exec.Command(dockerBinary, "start", "testing")
143
-	if out, _, err := runCommandWithOutput(runCmd); err == nil || !strings.Contains(out, "Cannot start a paused container, try unpause instead.") {
135
+	if out, _, err := dockerCmdWithError(c, "start", "testing"); err == nil || !strings.Contains(out, "Cannot start a paused container, try unpause instead.") {
144 136
 		c.Fatalf("an error should have been shown that you cannot start paused container: %s\n%v", out, err)
145 137
 	}
146
-
147 138
 }
148 139
 
149 140
 func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
150 141
 	// run a container named 'parent' and create two container link to `parent`
151
-	cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top")
152
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
153
-		c.Fatal(out, err)
154
-	}
142
+	dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
143
+
155 144
 	for _, container := range []string{"child_first", "child_second"} {
156
-		cmd = exec.Command(dockerBinary, "create", "--name", container, "--link", "parent:parent", "busybox", "top")
157
-		if out, _, err := runCommandWithOutput(cmd); err != nil {
158
-			c.Fatal(out, err)
159
-		}
145
+		dockerCmd(c, "create", "--name", container, "--link", "parent:parent", "busybox", "top")
160 146
 	}
161 147
 
162 148
 	// stop 'parent' container
163
-	cmd = exec.Command(dockerBinary, "stop", "parent")
164
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
165
-		c.Fatal(out, err)
166
-	}
149
+	dockerCmd(c, "stop", "parent")
150
+
167 151
 	out, err := inspectField("parent", "State.Running")
168 152
 	c.Assert(err, check.IsNil)
169 153
 	if out != "false" {
... ...
@@ -172,8 +131,7 @@ func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
172 172
 
173 173
 	// start all the three containers, container `child_first` start first which should be failed
174 174
 	// container 'parent' start second and then start container 'child_second'
175
-	cmd = exec.Command(dockerBinary, "start", "child_first", "parent", "child_second")
176
-	out, _, err = runCommandWithOutput(cmd)
175
+	out, _, err = dockerCmdWithError(c, "start", "child_first", "parent", "child_second")
177 176
 	if !strings.Contains(out, "Cannot start container child_first") || err == nil {
178 177
 		c.Fatal("Expected error but got none")
179 178
 	}
... ...
@@ -186,33 +144,22 @@ func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
186 186
 		}
187 187
 
188 188
 	}
189
-
190 189
 }
191 190
 
192 191
 func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
193
-
194
-	var cmd *exec.Cmd
195
-
196 192
 	// run  multiple containers to test
197 193
 	for _, container := range []string{"test1", "test2", "test3"} {
198
-		cmd = exec.Command(dockerBinary, "run", "-d", "--name", container, "busybox", "top")
199
-		if out, _, err := runCommandWithOutput(cmd); err != nil {
200
-			c.Fatal(out, err)
201
-		}
194
+		dockerCmd(c, "run", "-d", "--name", container, "busybox", "top")
202 195
 	}
203 196
 
204 197
 	// stop all the containers
205 198
 	for _, container := range []string{"test1", "test2", "test3"} {
206
-		cmd = exec.Command(dockerBinary, "stop", container)
207
-		if out, _, err := runCommandWithOutput(cmd); err != nil {
208
-			c.Fatal(out, err)
209
-		}
199
+		dockerCmd(c, "stop", container)
210 200
 	}
211 201
 
212 202
 	// test start and attach multiple containers at once, expected error
213 203
 	for _, option := range []string{"-a", "-i", "-ai"} {
214
-		cmd = exec.Command(dockerBinary, "start", option, "test1", "test2", "test3")
215
-		out, _, err := runCommandWithOutput(cmd)
204
+		out, _, err := dockerCmdWithError(c, "start", option, "test1", "test2", "test3")
216 205
 		if !strings.Contains(out, "You cannot start and attach multiple containers at once.") || err == nil {
217 206
 			c.Fatal("Expected error but got none")
218 207
 		}
... ...
@@ -228,5 +175,4 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
228 228
 			c.Fatal("Container running state wrong")
229 229
 		}
230 230
 	}
231
-
232 231
 }