Browse code

Merge pull request #12838 from fntlnz/test-cmd

Using dockerCmd when possible

David Calavera authored on 2015/06/03 06:12:22
Showing 3 changed files
... ...
@@ -76,13 +76,11 @@ func (s *DockerSuite) TestEventsContainerFailStartDie(c *check.C) {
76 76
 
77 77
 	out, _ := dockerCmd(c, "images", "-q")
78 78
 	image := strings.Split(out, "\n")[0]
79
-	eventsCmd := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg")
80
-	_, _, err := runCommandWithOutput(eventsCmd)
81
-	if err == nil {
79
+	if err := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg").Run(); err == nil {
82 80
 		c.Fatalf("Container run with command blerg should have failed, but it did not")
83 81
 	}
84 82
 
85
-	eventsCmd = exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
83
+	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
86 84
 	out, _, _ = runCommandWithOutput(eventsCmd)
87 85
 	events := strings.Split(out, "\n")
88 86
 	if len(events) <= 1 {
... ...
@@ -13,33 +13,17 @@ import (
13 13
 
14 14
 func (s *DockerSuite) TestPsListContainers(c *check.C) {
15 15
 
16
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
17
-	out, _, err := runCommandWithOutput(runCmd)
18
-	if err != nil {
19
-		c.Fatal(out, err)
20
-	}
16
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
21 17
 	firstID := strings.TrimSpace(out)
22 18
 
23
-	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
24
-	out, _, err = runCommandWithOutput(runCmd)
25
-	if err != nil {
26
-		c.Fatal(out, err)
27
-	}
19
+	out, _ = dockerCmd(c, "run", "-d", "busybox", "top")
28 20
 	secondID := strings.TrimSpace(out)
29 21
 
30 22
 	// not long running
31
-	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "true")
32
-	out, _, err = runCommandWithOutput(runCmd)
33
-	if err != nil {
34
-		c.Fatal(out, err)
35
-	}
23
+	out, _ = dockerCmd(c, "run", "-d", "busybox", "true")
36 24
 	thirdID := strings.TrimSpace(out)
37 25
 
38
-	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
39
-	out, _, err = runCommandWithOutput(runCmd)
40
-	if err != nil {
41
-		c.Fatal(out, err)
42
-	}
26
+	out, _ = dockerCmd(c, "run", "-d", "busybox", "top")
43 27
 	fourthID := strings.TrimSpace(out)
44 28
 
45 29
 	// make sure the second is running
... ...
@@ -48,10 +32,7 @@ func (s *DockerSuite) TestPsListContainers(c *check.C) {
48 48
 	}
49 49
 
50 50
 	// make sure third one is not running
51
-	runCmd = exec.Command(dockerBinary, "wait", thirdID)
52
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
53
-		c.Fatal(out, err)
54
-	}
51
+	dockerCmd(c, "wait", thirdID)
55 52
 
56 53
 	// make sure the forth is running
57 54
 	if err := waitRun(fourthID); err != nil {
... ...
@@ -59,23 +40,13 @@ func (s *DockerSuite) TestPsListContainers(c *check.C) {
59 59
 	}
60 60
 
61 61
 	// all
62
-	runCmd = exec.Command(dockerBinary, "ps", "-a")
63
-	out, _, err = runCommandWithOutput(runCmd)
64
-	if err != nil {
65
-		c.Fatal(out, err)
66
-	}
67
-
62
+	out, _ = dockerCmd(c, "ps", "-a")
68 63
 	if !assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}) {
69 64
 		c.Errorf("Container list is not in the correct order: %s", out)
70 65
 	}
71 66
 
72 67
 	// running
73
-	runCmd = exec.Command(dockerBinary, "ps")
74
-	out, _, err = runCommandWithOutput(runCmd)
75
-	if err != nil {
76
-		c.Fatal(out, err)
77
-	}
78
-
68
+	out, _ = dockerCmd(c, "ps")
79 69
 	if !assertContainerList(out, []string{fourthID, secondID, firstID}) {
80 70
 		c.Errorf("Container list is not in the correct order: %s", out)
81 71
 	}
... ...
@@ -83,154 +54,85 @@ func (s *DockerSuite) TestPsListContainers(c *check.C) {
83 83
 	// from here all flag '-a' is ignored
84 84
 
85 85
 	// limit
86
-	runCmd = exec.Command(dockerBinary, "ps", "-n=2", "-a")
87
-	out, _, err = runCommandWithOutput(runCmd)
88
-	if err != nil {
89
-		c.Fatal(out, err)
90
-	}
86
+	out, _ = dockerCmd(c, "ps", "-n=2", "-a")
91 87
 	expected := []string{fourthID, thirdID}
92
-
93 88
 	if !assertContainerList(out, expected) {
94 89
 		c.Errorf("Container list is not in the correct order: %s", out)
95 90
 	}
96 91
 
97
-	runCmd = exec.Command(dockerBinary, "ps", "-n=2")
98
-	out, _, err = runCommandWithOutput(runCmd)
99
-	if err != nil {
100
-		c.Fatal(out, err)
101
-	}
102
-
92
+	out, _ = dockerCmd(c, "ps", "-n=2")
103 93
 	if !assertContainerList(out, expected) {
104 94
 		c.Errorf("Container list is not in the correct order: %s", out)
105 95
 	}
106 96
 
107 97
 	// since
108
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-a")
109
-	out, _, err = runCommandWithOutput(runCmd)
110
-	if err != nil {
111
-		c.Fatal(out, err)
112
-	}
98
+	out, _ = dockerCmd(c, "ps", "--since", firstID, "-a")
113 99
 	expected = []string{fourthID, thirdID, secondID}
114
-
115 100
 	if !assertContainerList(out, expected) {
116 101
 		c.Errorf("Container list is not in the correct order: %s", out)
117 102
 	}
118 103
 
119
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID)
120
-	out, _, err = runCommandWithOutput(runCmd)
121
-	if err != nil {
122
-		c.Fatal(out, err)
123
-	}
124
-
104
+	out, _ = dockerCmd(c, "ps", "--since", firstID)
125 105
 	if !assertContainerList(out, expected) {
126 106
 		c.Errorf("Container list is not in the correct order: %s", out)
127 107
 	}
128 108
 
129 109
 	// before
130
-	runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID, "-a")
131
-	out, _, err = runCommandWithOutput(runCmd)
132
-	if err != nil {
133
-		c.Fatal(out, err)
134
-	}
110
+	out, _ = dockerCmd(c, "ps", "--before", thirdID, "-a")
135 111
 	expected = []string{secondID, firstID}
136
-
137 112
 	if !assertContainerList(out, expected) {
138 113
 		c.Errorf("Container list is not in the correct order: %s", out)
139 114
 	}
140 115
 
141
-	runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID)
142
-	out, _, err = runCommandWithOutput(runCmd)
143
-	if err != nil {
144
-		c.Fatal(out, err)
145
-	}
146
-
116
+	out, _ = dockerCmd(c, "ps", "--before", thirdID)
147 117
 	if !assertContainerList(out, expected) {
148 118
 		c.Errorf("Container list is not in the correct order: %s", out)
149 119
 	}
150 120
 
151 121
 	// since & before
152
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-a")
153
-	out, _, err = runCommandWithOutput(runCmd)
154
-	if err != nil {
155
-		c.Fatal(out, err)
156
-	}
122
+	out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-a")
157 123
 	expected = []string{thirdID, secondID}
158
-
159 124
 	if !assertContainerList(out, expected) {
160 125
 		c.Errorf("Container list is not in the correct order: %s", out)
161 126
 	}
162 127
 
163
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID)
164
-	out, _, err = runCommandWithOutput(runCmd)
165
-	if err != nil {
166
-		c.Fatal(out, err)
167
-	}
128
+	out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID)
168 129
 	if !assertContainerList(out, expected) {
169 130
 		c.Errorf("Container list is not in the correct order: %s", out)
170 131
 	}
171 132
 
172 133
 	// since & limit
173
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2", "-a")
174
-	out, _, err = runCommandWithOutput(runCmd)
175
-	if err != nil {
176
-		c.Fatal(out, err)
177
-	}
134
+	out, _ = dockerCmd(c, "ps", "--since", firstID, "-n=2", "-a")
178 135
 	expected = []string{fourthID, thirdID}
179 136
 
180 137
 	if !assertContainerList(out, expected) {
181 138
 		c.Errorf("Container list is not in the correct order: %s", out)
182 139
 	}
183 140
 
184
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2")
185
-	out, _, err = runCommandWithOutput(runCmd)
186
-	if err != nil {
187
-		c.Fatal(out, err)
188
-	}
189
-
141
+	out, _ = dockerCmd(c, "ps", "--since", firstID, "-n=2")
190 142
 	if !assertContainerList(out, expected) {
191 143
 		c.Errorf("Container list is not in the correct order: %s", out)
192 144
 	}
193 145
 
194 146
 	// before & limit
195
-	runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1", "-a")
196
-	out, _, err = runCommandWithOutput(runCmd)
197
-	if err != nil {
198
-		c.Fatal(out, err)
199
-	}
147
+	out, _ = dockerCmd(c, "ps", "--before", fourthID, "-n=1", "-a")
200 148
 	expected = []string{thirdID}
201
-
202 149
 	if !assertContainerList(out, expected) {
203 150
 		c.Errorf("Container list is not in the correct order: %s", out)
204 151
 	}
205 152
 
206
-	runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1")
207
-	out, _, err = runCommandWithOutput(runCmd)
208
-	if err != nil {
209
-		c.Fatal(out, err)
210
-	}
211
-
153
+	out, _ = dockerCmd(c, "ps", "--before", fourthID, "-n=1")
212 154
 	if !assertContainerList(out, expected) {
213 155
 		c.Errorf("Container list is not in the correct order: %s", out)
214 156
 	}
215 157
 
216
-	// since & before & limit
217
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a")
218
-	out, _, err = runCommandWithOutput(runCmd)
219
-	if err != nil {
220
-		c.Fatal(out, err)
221
-	}
158
+	out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a")
222 159
 	expected = []string{thirdID}
223
-
224 160
 	if !assertContainerList(out, expected) {
225 161
 		c.Errorf("Container list is not in the correct order: %s", out)
226 162
 	}
227 163
 
228
-	runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1")
229
-	out, _, err = runCommandWithOutput(runCmd)
230
-	if err != nil {
231
-		c.Fatal(out, err)
232
-	}
233
-
164
+	out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-n=1")
234 165
 	if !assertContainerList(out, expected) {
235 166
 		c.Errorf("Container list is not in the correct order: %s", out)
236 167
 	}
... ...
@@ -255,10 +157,9 @@ func assertContainerList(out string, expected []string) bool {
255 255
 }
256 256
 
257 257
 func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
258
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
259
-	runCommandWithOutput(cmd)
260
-	cmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
261
-	baseOut, _, err := runCommandWithOutput(cmd)
258
+	dockerCmd(c, "run", "-d", "busybox", "echo", "hello")
259
+
260
+	baseOut, _ := dockerCmd(c, "ps", "-s", "-n=1")
262 261
 	baseLines := strings.Split(strings.Trim(baseOut, "\n "), "\n")
263 262
 	baseSizeIndex := strings.Index(baseLines[0], "SIZE")
264 263
 	baseFoundsize := baseLines[1][baseSizeIndex:]
... ...
@@ -268,17 +169,14 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
268 268
 	}
269 269
 
270 270
 	name := "test_size"
271
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
272
-	out, _, err := runCommandWithOutput(runCmd)
273
-	if err != nil {
274
-		c.Fatal(out, err)
275
-	}
271
+	out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
276 272
 	id, err := getIDByName(name)
277 273
 	if err != nil {
278 274
 		c.Fatal(err)
279 275
 	}
280 276
 
281
-	runCmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
277
+	runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1")
278
+
282 279
 	wait := make(chan struct{})
283 280
 	go func() {
284 281
 		out, _, err = runCommandWithOutput(runCmd)
... ...
@@ -315,43 +213,24 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
315 315
 	// this is because paused containers can't be controlled by signals
316 316
 
317 317
 	// start exited container
318
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
319
-	out, _, err := runCommandWithOutput(runCmd)
320
-	if err != nil {
321
-		c.Fatal(out, err)
322
-	}
318
+	out, _ := dockerCmd(c, "run", "-d", "busybox")
323 319
 	firstID := strings.TrimSpace(out)
324 320
 
325 321
 	// make sure the exited cintainer is not running
326
-	runCmd = exec.Command(dockerBinary, "wait", firstID)
327
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
328
-		c.Fatal(out, err)
329
-	}
322
+	dockerCmd(c, "wait", firstID)
330 323
 
331 324
 	// start running container
332
-	runCmd = exec.Command(dockerBinary, "run", "-itd", "busybox")
333
-	out, _, err = runCommandWithOutput(runCmd)
334
-	if err != nil {
335
-		c.Fatal(out, err)
336
-	}
325
+	out, _ = dockerCmd(c, "run", "-itd", "busybox")
337 326
 	secondID := strings.TrimSpace(out)
338 327
 
339 328
 	// filter containers by exited
340
-	runCmd = exec.Command(dockerBinary, "ps", "-q", "--filter=status=exited")
341
-	out, _, err = runCommandWithOutput(runCmd)
342
-	if err != nil {
343
-		c.Fatal(out, err)
344
-	}
329
+	out, _ = dockerCmd(c, "ps", "-q", "--filter=status=exited")
345 330
 	containerOut := strings.TrimSpace(out)
346 331
 	if containerOut != firstID[:12] {
347 332
 		c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
348 333
 	}
349 334
 
350
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=status=running")
351
-	out, _, err = runCommandWithOutput(runCmd)
352
-	if err != nil {
353
-		c.Fatal(out, err)
354
-	}
335
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=status=running")
355 336
 	containerOut = strings.TrimSpace(out)
356 337
 	if containerOut != secondID[:12] {
357 338
 		c.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)
... ...
@@ -362,24 +241,14 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
362 362
 func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
363 363
 
364 364
 	// start container
365
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
366
-	out, _, err := runCommandWithOutput(runCmd)
367
-	if err != nil {
368
-		c.Fatal(out, err)
369
-	}
365
+	out, _ := dockerCmd(c, "run", "-d", "busybox")
370 366
 	firstID := strings.TrimSpace(out)
371 367
 
372 368
 	// start another container
373
-	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
374
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
375
-		c.Fatal(out, err)
376
-	}
369
+	dockerCmd(c, "run", "-d", "busybox", "top")
377 370
 
378 371
 	// filter containers by id
379
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=id="+firstID)
380
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
381
-		c.Fatal(out, err)
382
-	}
372
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
383 373
 	containerOut := strings.TrimSpace(out)
384 374
 	if containerOut != firstID[:12] {
385 375
 		c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
... ...
@@ -390,24 +259,14 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
390 390
 func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
391 391
 
392 392
 	// start container
393
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name=a_name_to_match", "busybox")
394
-	out, _, err := runCommandWithOutput(runCmd)
395
-	if err != nil {
396
-		c.Fatal(out, err)
397
-	}
393
+	out, _ := dockerCmd(c, "run", "-d", "--name=a_name_to_match", "busybox")
398 394
 	firstID := strings.TrimSpace(out)
399 395
 
400 396
 	// start another container
401
-	runCmd = exec.Command(dockerBinary, "run", "-d", "--name=b_name_to_match", "busybox", "top")
402
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
403
-		c.Fatal(out, err)
404
-	}
397
+	dockerCmd(c, "run", "-d", "--name=b_name_to_match", "busybox", "top")
405 398
 
406 399
 	// filter containers by name
407
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=name=a_name_to_match")
408
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
409
-		c.Fatal(out, err)
410
-	}
400
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
411 401
 	containerOut := strings.TrimSpace(out)
412 402
 	if containerOut != firstID[:12] {
413 403
 		c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
... ...
@@ -417,62 +276,40 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
417 417
 
418 418
 func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
419 419
 	// start container
420
-	runCmd := exec.Command(dockerBinary, "run", "-d", "-l", "match=me", "-l", "second=tag", "busybox")
421
-	out, _, err := runCommandWithOutput(runCmd)
422
-	if err != nil {
423
-		c.Fatal(out, err)
424
-	}
420
+	out, _ := dockerCmd(c, "run", "-d", "-l", "match=me", "-l", "second=tag", "busybox")
425 421
 	firstID := strings.TrimSpace(out)
426 422
 
427 423
 	// start another container
428
-	runCmd = exec.Command(dockerBinary, "run", "-d", "-l", "match=me too", "busybox")
429
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
430
-		c.Fatal(out, err)
431
-	}
424
+	out, _ = dockerCmd(c, "run", "-d", "-l", "match=me too", "busybox")
432 425
 	secondID := strings.TrimSpace(out)
433 426
 
434 427
 	// start third container
435
-	runCmd = exec.Command(dockerBinary, "run", "-d", "-l", "nomatch=me", "busybox")
436
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
437
-		c.Fatal(out, err)
438
-	}
428
+	out, _ = dockerCmd(c, "run", "-d", "-l", "nomatch=me", "busybox")
439 429
 	thirdID := strings.TrimSpace(out)
440 430
 
441 431
 	// filter containers by exact match
442
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
443
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
444
-		c.Fatal(out, err)
445
-	}
432
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
446 433
 	containerOut := strings.TrimSpace(out)
447 434
 	if containerOut != firstID {
448 435
 		c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
449 436
 	}
450 437
 
451 438
 	// filter containers by two labels
452
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
453
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
454
-		c.Fatal(out, err)
455
-	}
439
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
456 440
 	containerOut = strings.TrimSpace(out)
457 441
 	if containerOut != firstID {
458 442
 		c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
459 443
 	}
460 444
 
461 445
 	// filter containers by two labels, but expect not found because of AND behavior
462
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
463
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
464
-		c.Fatal(out, err)
465
-	}
446
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
466 447
 	containerOut = strings.TrimSpace(out)
467 448
 	if containerOut != "" {
468 449
 		c.Fatalf("Expected nothing, got %s for exited filter, output: %q", containerOut, out)
469 450
 	}
470 451
 
471 452
 	// filter containers by exact key
472
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
473
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
474
-		c.Fatal(out, err)
475
-	}
453
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
476 454
 	containerOut = strings.TrimSpace(out)
477 455
 	if (!strings.Contains(containerOut, firstID) || !strings.Contains(containerOut, secondID)) || strings.Contains(containerOut, thirdID) {
478 456
 		c.Fatalf("Expected ids %s,%s, got %s for exited filter, output: %q", firstID, secondID, containerOut, out)
... ...
@@ -481,33 +318,25 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
481 481
 
482 482
 func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
483 483
 
484
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
485
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
486
-		c.Fatal(out, err)
487
-	}
484
+	dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
488 485
 
489
-	runCmd = exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
490
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
491
-		c.Fatal(out, err)
492
-	}
486
+	dockerCmd(c, "run", "--name", "zero1", "busybox", "true")
493 487
 	firstZero, err := getIDByName("zero1")
494 488
 	if err != nil {
495 489
 		c.Fatal(err)
496 490
 	}
497 491
 
498
-	runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true")
499
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
500
-		c.Fatal(out, err)
501
-	}
492
+	dockerCmd(c, "run", "--name", "zero2", "busybox", "true")
502 493
 	secondZero, err := getIDByName("zero2")
503 494
 	if err != nil {
504 495
 		c.Fatal(err)
505 496
 	}
506 497
 
507
-	runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
498
+	runCmd := exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
508 499
 	if out, _, err := runCommandWithOutput(runCmd); err == nil {
509 500
 		c.Fatal("Should fail.", out, err)
510 501
 	}
502
+
511 503
 	firstNonZero, err := getIDByName("nonzero1")
512 504
 	if err != nil {
513 505
 		c.Fatal(err)
... ...
@@ -523,11 +352,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
523 523
 	}
524 524
 
525 525
 	// filter containers by exited=0
526
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
527
-	out, _, err := runCommandWithOutput(runCmd)
528
-	if err != nil {
529
-		c.Fatal(out, err)
530
-	}
526
+	out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
531 527
 	ids := strings.Split(strings.TrimSpace(out), "\n")
532 528
 	if len(ids) != 2 {
533 529
 		c.Fatalf("Should be 2 zero exited containers got %d: %s", len(ids), out)
... ...
@@ -539,11 +364,7 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
539 539
 		c.Fatalf("Second in list should be %q, got %q", firstZero, ids[1])
540 540
 	}
541 541
 
542
-	runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
543
-	out, _, err = runCommandWithOutput(runCmd)
544
-	if err != nil {
545
-		c.Fatal(out, err)
546
-	}
542
+	out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
547 543
 	ids = strings.Split(strings.TrimSpace(out), "\n")
548 544
 	if len(ids) != 2 {
549 545
 		c.Fatalf("Should be 2 zero exited containers got %d", len(ids))
... ...
@@ -650,15 +471,9 @@ func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
650 650
 func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
651 651
 
652 652
 	portRange := "3800-3900"
653
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top"))
654
-	if err != nil {
655
-		c.Fatal(out, err)
656
-	}
653
+	dockerCmd(c, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top")
657 654
 
658
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "ps"))
659
-	if err != nil {
660
-		c.Fatal(out, err)
661
-	}
655
+	out, _ := dockerCmd(c, "ps")
662 656
 
663 657
 	// check that the port range is in the output
664 658
 	if !strings.Contains(string(out), portRange) {
... ...
@@ -552,9 +552,7 @@ func pullImageIfNotExist(image string) (err error) {
552 552
 
553 553
 func dockerCmd(c *check.C, args ...string) (string, int) {
554 554
 	out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...))
555
-	if err != nil {
556
-		c.Fatalf("%q failed with errors: %s, %v", strings.Join(args, " "), out, err)
557
-	}
555
+	c.Assert(err, check.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(args, " "), out, err))
558 556
 	return out, status
559 557
 }
560 558