Browse code

dockerCmd when possible

Addresses: #14603

integration-cli/docker_cli_daemon_experimental_test.go (hqhq)
integration-cli/docker_cli_daemon_test.go (hqhq)
integration-cli/docker_cli_diff_test.go (hqhq)
integration-cli/docker_cli_events_test.go (hqhq)
integration-cli/docker_cli_events_unix_test.go (hqhq)
integration-cli/docker_cli_exec_test.go (hqhq)
integration-cli/docker_cli_exec_unix_test.go (hqhq)
integration-cli/docker_cli_experimental_test.go (hqhq)
integration-cli/docker_cli_export_import_test.go (hqhq)
integration-cli/docker_cli_help_test.go (hqhq)
integration-cli/docker_cli_history_test.go (hqhq)
integration-cli/docker_cli_images_test.go (hqhq)
integration-cli/docker_cli_import_test.go (hqhq)
integration-cli/docker_cli_info_test.go (hqhq)
integration-cli/docker_cli_inspect_test.go (hqhq)
integration-cli/docker_cli_kill_test.go (hqhq)

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>

Qiang Huang authored on 2015/07/20 15:55:40
Showing 13 changed files
... ...
@@ -1276,13 +1276,12 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
1276 1276
 	}
1277 1277
 
1278 1278
 	args := append(dargs, "run", "-d", "--name", "container1", "busybox", "top")
1279
-	_, err := runCommand(exec.Command(dockerBinary, args...))
1280
-	c.Assert(err, check.IsNil)
1279
+	dockerCmd(c, args...)
1281 1280
 
1282 1281
 	args = append(dargs, "run", "--rm", "--link", "container1:alias1", "busybox", "sh", "-c")
1283 1282
 	pingCmd := "ping -c 1 %s -W 1"
1284 1283
 	args = append(args, fmt.Sprintf(pingCmd, "alias1"))
1285
-	_, err = runCommand(exec.Command(dockerBinary, args...))
1284
+	_, _, err := dockerCmdWithError(c, args...)
1286 1285
 
1287 1286
 	if expectFailure {
1288 1287
 		c.Assert(err, check.NotNil)
... ...
@@ -1291,7 +1290,7 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
1291 1291
 	}
1292 1292
 
1293 1293
 	args = append(dargs, "rm", "-f", "container1")
1294
-	runCommand(exec.Command(dockerBinary, args...))
1294
+	dockerCmd(c, args...)
1295 1295
 }
1296 1296
 
1297 1297
 func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) {
... ...
@@ -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,19 +9,10 @@ import (
10 10
 // ensure that an added file shows up in docker diff
11 11
 func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
12 12
 	containerCmd := `echo foo > /root/bar`
13
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
14
-	out, _, err := runCommandWithOutput(runCmd)
15
-	if err != nil {
16
-		c.Fatalf("failed to start the container: %s, %v", out, err)
17
-	}
13
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
18 14
 
19 15
 	cleanCID := strings.TrimSpace(out)
20
-
21
-	diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
22
-	out, _, err = runCommandWithOutput(diffCmd)
23
-	if err != nil {
24
-		c.Fatalf("failed to run diff: %s %v", out, err)
25
-	}
16
+	out, _ = dockerCmd(c, "diff", cleanCID)
26 17
 
27 18
 	found := false
28 19
 	for _, line := range strings.Split(out, "\n") {
... ...
@@ -45,20 +35,10 @@ func (s *DockerSuite) TestDiffEnsureDockerinitFilesAreIgnored(c *check.C) {
45 45
 	// we might not run into this problem from the first run, so start a few containers
46 46
 	for i := 0; i < containerCount; i++ {
47 47
 		containerCmd := `echo foo > /root/bar`
48
-		runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
49
-		out, _, err := runCommandWithOutput(runCmd)
50
-
51
-		if err != nil {
52
-			c.Fatal(out, err)
53
-		}
48
+		out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
54 49
 
55 50
 		cleanCID := strings.TrimSpace(out)
56
-
57
-		diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
58
-		out, _, err = runCommandWithOutput(diffCmd)
59
-		if err != nil {
60
-			c.Fatalf("failed to run diff: %s, %v", out, err)
61
-		}
51
+		out, _ = dockerCmd(c, "diff", cleanCID)
62 52
 
63 53
 		for _, filename := range dockerinitFiles {
64 54
 			if strings.Contains(out, filename) {
... ...
@@ -69,19 +49,10 @@ func (s *DockerSuite) TestDiffEnsureDockerinitFilesAreIgnored(c *check.C) {
69 69
 }
70 70
 
71 71
 func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) {
72
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "0")
73
-	out, _, err := runCommandWithOutput(runCmd)
74
-	if err != nil {
75
-		c.Fatal(out, err)
76
-	}
72
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "0")
77 73
 
78 74
 	cleanCID := strings.TrimSpace(out)
79
-
80
-	diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
81
-	out, _, err = runCommandWithOutput(diffCmd)
82
-	if err != nil {
83
-		c.Fatalf("failed to run diff: %s, %v", out, err)
84
-	}
75
+	out, _ = dockerCmd(c, "diff", cleanCID)
85 76
 
86 77
 	expected := map[string]bool{
87 78
 		"C /dev":         true,
... ...
@@ -111,7 +82,7 @@ func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) {
111 111
 
112 112
 // https://github.com/docker/docker/pull/14381#discussion_r33859347
113 113
 func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) {
114
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "diff", ""))
114
+	out, _, err := dockerCmdWithError(c, "diff", "")
115 115
 	c.Assert(err, check.NotNil)
116 116
 	c.Assert(strings.TrimSpace(out), check.Equals, "Container name cannot be empty")
117 117
 }
... ...
@@ -34,11 +34,7 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
34 34
 	// --since=$start must contain only the 'untag' event
35 35
 	for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} {
36 36
 		since, until := f(start), f(end)
37
-		cmd := exec.Command(dockerBinary, "events", "--since="+since, "--until="+until)
38
-		out, _, err := runCommandWithOutput(cmd)
39
-		if err != nil {
40
-			c.Fatalf("docker events cmd failed: %v\nout=%s", err, out)
41
-		}
37
+		out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until)
42 38
 		events := strings.Split(strings.TrimSpace(out), "\n")
43 39
 		if len(events) != 2 {
44 40
 			c.Fatalf("unexpected events, was expecting only 2 events tag/untag (since=%s, until=%s) out=%s", since, until, out)
... ...
@@ -77,12 +73,11 @@ func (s *DockerSuite) TestEventsContainerFailStartDie(c *check.C) {
77 77
 
78 78
 	out, _ := dockerCmd(c, "images", "-q")
79 79
 	image := strings.Split(out, "\n")[0]
80
-	if err := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg").Run(); err == nil {
80
+	if _, _, err := dockerCmdWithError(c, "run", "--name", "testeventdie", image, "blerg"); err == nil {
81 81
 		c.Fatalf("Container run with command blerg should have failed, but it did not")
82 82
 	}
83 83
 
84
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
85
-	out, _, _ = runCommandWithOutput(eventsCmd)
84
+	out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
86 85
 	events := strings.Split(out, "\n")
87 86
 	if len(events) <= 1 {
88 87
 		c.Fatalf("Missing expected event")
... ...
@@ -123,8 +118,7 @@ func (s *DockerSuite) TestEventsLimit(c *check.C) {
123 123
 		}
124 124
 	}
125 125
 
126
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
127
-	out, _, _ := runCommandWithOutput(eventsCmd)
126
+	out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
128 127
 	events := strings.Split(out, "\n")
129 128
 	nEvents := len(events) - 1
130 129
 	if nEvents != 64 {
... ...
@@ -134,11 +128,7 @@ func (s *DockerSuite) TestEventsLimit(c *check.C) {
134 134
 
135 135
 func (s *DockerSuite) TestEventsContainerEvents(c *check.C) {
136 136
 	dockerCmd(c, "run", "--rm", "busybox", "true")
137
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
138
-	out, exitCode, err := runCommandWithOutput(eventsCmd)
139
-	if exitCode != 0 || err != nil {
140
-		c.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
141
-	}
137
+	out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
142 138
 	events := strings.Split(out, "\n")
143 139
 	events = events[:len(events)-1]
144 140
 	if len(events) < 5 {
... ...
@@ -171,12 +161,8 @@ func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) {
171 171
 	dockerCmd(c, "run", "--rm", "busybox", "true")
172 172
 	timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano)
173 173
 	timeBeginning = strings.Replace(timeBeginning, "Z", ".000000000Z", -1)
174
-	eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since='%s'", timeBeginning),
174
+	out, _ := dockerCmd(c, "events", fmt.Sprintf("--since='%s'", timeBeginning),
175 175
 		fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
176
-	out, exitCode, err := runCommandWithOutput(eventsCmd)
177
-	if exitCode != 0 || err != nil {
178
-		c.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
179
-	}
180 176
 	events := strings.Split(out, "\n")
181 177
 	events = events[:len(events)-1]
182 178
 	if len(events) < 5 {
... ...
@@ -217,11 +203,7 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
217 217
 	if err := deleteImages(name); err != nil {
218 218
 		c.Fatal(err)
219 219
 	}
220
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
221
-	out, exitCode, err := runCommandWithOutput(eventsCmd)
222
-	if exitCode != 0 || err != nil {
223
-		c.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
224
-	}
220
+	out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
225 221
 	events := strings.Split(out, "\n")
226 222
 
227 223
 	events = events[:len(events)-1]
... ...
@@ -244,11 +226,9 @@ func (s *DockerSuite) TestEventsImageTag(c *check.C) {
244 244
 	image := "testimageevents:tag"
245 245
 	dockerCmd(c, "tag", "busybox", image)
246 246
 
247
-	eventsCmd := exec.Command(dockerBinary, "events",
247
+	out, _ := dockerCmd(c, "events",
248 248
 		fmt.Sprintf("--since=%d", since),
249 249
 		fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
250
-	out, _, err := runCommandWithOutput(eventsCmd)
251
-	c.Assert(err, check.IsNil)
252 250
 
253 251
 	events := strings.Split(strings.TrimSpace(out), "\n")
254 252
 	if len(events) != 1 {
... ...
@@ -267,15 +247,11 @@ func (s *DockerSuite) TestEventsImagePull(c *check.C) {
267 267
 	since := daemonTime(c).Unix()
268 268
 	testRequires(c, Network)
269 269
 
270
-	pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
271
-	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
272
-		c.Fatalf("pulling the hello-world image from has failed: %s, %v", out, err)
273
-	}
270
+	dockerCmd(c, "pull", "hello-world")
274 271
 
275
-	eventsCmd := exec.Command(dockerBinary, "events",
272
+	out, _ := dockerCmd(c, "events",
276 273
 		fmt.Sprintf("--since=%d", since),
277 274
 		fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
278
-	out, _, _ := runCommandWithOutput(eventsCmd)
279 275
 
280 276
 	events := strings.Split(strings.TrimSpace(out), "\n")
281 277
 	event := strings.TrimSpace(events[len(events)-1])
... ...
@@ -313,11 +289,7 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
313 313
 		}
314 314
 	}()
315 315
 
316
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
317
-	out, _, err := runCommandWithOutput(runCmd)
318
-	if err != nil {
319
-		c.Fatal("failed to create a container", out, err)
320
-	}
316
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
321 317
 	cleanedContainerID := strings.TrimSpace(out)
322 318
 
323 319
 	out, _, err = runCommandPipelineWithOutput(
... ...
@@ -352,24 +324,12 @@ func (s *DockerSuite) TestEventsFilters(c *check.C) {
352 352
 	}
353 353
 
354 354
 	since := daemonTime(c).Unix()
355
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
356
-	if err != nil {
357
-		c.Fatal(out, err)
358
-	}
359
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
360
-	if err != nil {
361
-		c.Fatal(out, err)
362
-	}
363
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die"))
364
-	if err != nil {
365
-		c.Fatalf("Failed to get events: %s", err)
366
-	}
355
+	dockerCmd(c, "run", "--rm", "busybox", "true")
356
+	dockerCmd(c, "run", "--rm", "busybox", "true")
357
+	out, _ := dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die")
367 358
 	parseEvents(out, "die")
368 359
 
369
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die", "--filter", "event=start"))
370
-	if err != nil {
371
-		c.Fatalf("Failed to get events: %s", err)
372
-	}
360
+	out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die", "--filter", "event=start")
373 361
 	parseEvents(out, "((die)|(start))")
374 362
 
375 363
 	// make sure we at least got 2 start events
... ...
@@ -383,24 +343,14 @@ func (s *DockerSuite) TestEventsFilters(c *check.C) {
383 383
 func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
384 384
 	since := daemonTime(c).Unix()
385 385
 
386
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "-d", "busybox:latest", "true"))
387
-	if err != nil {
388
-		c.Fatal(out, err)
389
-	}
386
+	out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true")
390 387
 	container1 := strings.TrimSpace(out)
391 388
 
392
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_2", "-d", "busybox", "true"))
393
-	if err != nil {
394
-		c.Fatal(out, err)
395
-	}
389
+	out, _ = dockerCmd(c, "run", "--name", "container_2", "-d", "busybox", "true")
396 390
 	container2 := strings.TrimSpace(out)
397 391
 
398 392
 	name := "busybox"
399
-	eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", fmt.Sprintf("image=%s", name))
400
-	out, _, err = runCommandWithOutput(eventsCmd)
401
-	if err != nil {
402
-		c.Fatalf("Failed to get events, error: %s(%s)", err, out)
403
-	}
393
+	out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", fmt.Sprintf("image=%s", name))
404 394
 	events := strings.Split(out, "\n")
405 395
 	events = events[:len(events)-1]
406 396
 	if len(events) == 0 {
... ...
@@ -427,10 +377,7 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
427 427
 	nameID := make(map[string]string)
428 428
 
429 429
 	for _, name := range []string{"container_1", "container_2"} {
430
-		out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", name, "busybox", "true"))
431
-		if err != nil {
432
-			c.Fatalf("Error: %v, Output: %s", err, out)
433
-		}
430
+		dockerCmd(c, "run", "--name", name, "busybox", "true")
434 431
 		id, err := inspectField(name, "Id")
435 432
 		if err != nil {
436 433
 			c.Fatal(err)
... ...
@@ -461,30 +408,19 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
461 461
 
462 462
 	for name, ID := range nameID {
463 463
 		// filter by names
464
-		eventsCmd := exec.Command(dockerBinary, "events", "--since", since, "--until", until, "--filter", "container="+name)
465
-		out, _, err := runCommandWithOutput(eventsCmd)
466
-		if err != nil {
467
-			c.Fatal(err)
468
-		}
469
-
464
+		out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name)
470 465
 		events := strings.Split(strings.TrimSuffix(out, "\n"), "\n")
471 466
 		if err := checkEvents(ID, events); err != nil {
472 467
 			c.Fatal(err)
473 468
 		}
474 469
 
475 470
 		// filter by ID's
476
-		eventsCmd = exec.Command(dockerBinary, "events", "--since", since, "--until", until, "--filter", "container="+ID)
477
-		out, _, err = runCommandWithOutput(eventsCmd)
478
-		if err != nil {
479
-			c.Fatal(err)
480
-		}
481
-
471
+		out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID)
482 472
 		events = strings.Split(strings.TrimSuffix(out, "\n"), "\n")
483 473
 		if err := checkEvents(ID, events); err != nil {
484 474
 			c.Fatal(err)
485 475
 		}
486 476
 	}
487
-
488 477
 }
489 478
 
490 479
 func (s *DockerSuite) TestEventsStreaming(c *check.C) {
... ...
@@ -529,11 +465,7 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
529 529
 		}
530 530
 	}()
531 531
 
532
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox:latest", "true")
533
-	out, _, err := runCommandWithOutput(runCmd)
534
-	if err != nil {
535
-		c.Fatal(out, err)
536
-	}
532
+	out, _ := dockerCmd(c, "run", "-d", "busybox:latest", "true")
537 533
 	cleanedContainerID := strings.TrimSpace(out)
538 534
 	id <- cleanedContainerID
539 535
 
... ...
@@ -558,11 +490,7 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
558 558
 		// ignore, done
559 559
 	}
560 560
 
561
-	rmCmd := exec.Command(dockerBinary, "rm", cleanedContainerID)
562
-	out, _, err = runCommandWithOutput(rmCmd)
563
-	if err != nil {
564
-		c.Fatal(out, err)
565
-	}
561
+	dockerCmd(c, "rm", cleanedContainerID)
566 562
 
567 563
 	select {
568 564
 	case <-time.After(5 * time.Second):
... ...
@@ -575,32 +503,14 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
575 575
 func (s *DockerSuite) TestEventsCommit(c *check.C) {
576 576
 	since := daemonTime(c).Unix()
577 577
 
578
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
579
-	out, _, err := runCommandWithOutput(runCmd)
580
-	if err != nil {
581
-		c.Fatalf("Couldn't run top: %s\n%q", out, err)
582
-	}
578
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
583 579
 	cID := strings.TrimSpace(out)
584 580
 	c.Assert(waitRun(cID), check.IsNil)
585 581
 
586
-	cmd := exec.Command(dockerBinary, "commit", "-m", "test", cID)
587
-	out, _, err = runCommandWithOutput(cmd)
588
-	if err != nil {
589
-		c.Fatalf("Couldn't commit: %s\n%q", out, err)
590
-	}
591
-
592
-	cmd = exec.Command(dockerBinary, "stop", cID)
593
-	out, _, err = runCommandWithOutput(cmd)
594
-	if err != nil {
595
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
596
-	}
597
-
598
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
599
-	out, _, err = runCommandWithOutput(cmd)
600
-	if err != nil {
601
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
602
-	}
582
+	dockerCmd(c, "commit", "-m", "test", cID)
583
+	dockerCmd(c, "stop", cID)
603 584
 
585
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
604 586
 	if !strings.Contains(out, " commit\n") {
605 587
 		c.Fatalf("Missing 'commit' log event\n%s", out)
606 588
 	}
... ...
@@ -616,24 +526,10 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) {
616 616
 		c.Fatalf("Couldn't create image: %q", err)
617 617
 	}
618 618
 
619
-	runCmd := exec.Command(dockerBinary, "run", "--name=cptest", id, "true")
620
-	out, _, err := runCommandWithOutput(runCmd)
621
-	if err != nil {
622
-		c.Fatalf("Couldn't run top: %s\n%q", out, err)
623
-	}
624
-
625
-	cmd := exec.Command(dockerBinary, "cp", "cptest:/tmp/file", "-")
626
-	out, _, err = runCommandWithOutput(cmd)
627
-	if err != nil {
628
-		c.Fatalf("Failed getting file:%q\n%q", out, err)
629
-	}
630
-
631
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
632
-	out, _, err = runCommandWithOutput(cmd)
633
-	if err != nil {
634
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
635
-	}
619
+	dockerCmd(c, "run", "--name=cptest", id, "true")
620
+	dockerCmd(c, "cp", "cptest:/tmp/file", "-")
636 621
 
622
+	out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
637 623
 	if !strings.Contains(out, " copy\n") {
638 624
 		c.Fatalf("Missing 'copy' log event\n%s", out)
639 625
 	}
... ...
@@ -642,11 +538,7 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) {
642 642
 func (s *DockerSuite) TestEventsResize(c *check.C) {
643 643
 	since := daemonTime(c).Unix()
644 644
 
645
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
646
-	out, _, err := runCommandWithOutput(runCmd)
647
-	if err != nil {
648
-		c.Fatalf("Couldn't run top: %s\n%q", out, err)
649
-	}
645
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
650 646
 	cID := strings.TrimSpace(out)
651 647
 	c.Assert(waitRun(cID), check.IsNil)
652 648
 
... ...
@@ -655,18 +547,9 @@ func (s *DockerSuite) TestEventsResize(c *check.C) {
655 655
 	c.Assert(status, check.Equals, http.StatusOK)
656 656
 	c.Assert(err, check.IsNil)
657 657
 
658
-	cmd := exec.Command(dockerBinary, "stop", cID)
659
-	out, _, err = runCommandWithOutput(cmd)
660
-	if err != nil {
661
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
662
-	}
663
-
664
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
665
-	out, _, err = runCommandWithOutput(cmd)
666
-	if err != nil {
667
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
668
-	}
658
+	dockerCmd(c, "stop", cID)
669 659
 
660
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
670 661
 	if !strings.Contains(out, " resize\n") {
671 662
 		c.Fatalf("Missing 'resize' log event\n%s", out)
672 663
 	}
... ...
@@ -700,18 +583,9 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
700 700
 
701 701
 	c.Assert(stdin.Close(), check.IsNil)
702 702
 
703
-	cmd = exec.Command(dockerBinary, "stop", cID)
704
-	out, _, err = runCommandWithOutput(cmd)
705
-	if err != nil {
706
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
707
-	}
708
-
709
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
710
-	out, _, err = runCommandWithOutput(cmd)
711
-	if err != nil {
712
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
713
-	}
703
+	dockerCmd(c, "stop", cID)
714 704
 
705
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
715 706
 	if !strings.Contains(out, " attach\n") {
716 707
 		c.Fatalf("Missing 'attach' log event\n%s", out)
717 708
 	}
... ...
@@ -720,24 +594,10 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
720 720
 func (s *DockerSuite) TestEventsRename(c *check.C) {
721 721
 	since := daemonTime(c).Unix()
722 722
 
723
-	runCmd := exec.Command(dockerBinary, "run", "--name", "oldName", "busybox", "true")
724
-	out, _, err := runCommandWithOutput(runCmd)
725
-	if err != nil {
726
-		c.Fatalf("Couldn't run true: %s\n%q", out, err)
727
-	}
728
-
729
-	renameCmd := exec.Command(dockerBinary, "rename", "oldName", "newName")
730
-	out, _, err = runCommandWithOutput(renameCmd)
731
-	if err != nil {
732
-		c.Fatalf("Couldn't rename: %s\n%q", out, err)
733
-	}
734
-
735
-	cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since)))
736
-	out, _, err = runCommandWithOutput(cmd)
737
-	if err != nil {
738
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
739
-	}
723
+	dockerCmd(c, "run", "--name", "oldName", "busybox", "true")
724
+	dockerCmd(c, "rename", "oldName", "newName")
740 725
 
726
+	out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since)))
741 727
 	if !strings.Contains(out, " rename\n") {
742 728
 		c.Fatalf("Missing 'rename' log event\n%s", out)
743 729
 	}
... ...
@@ -746,32 +606,14 @@ func (s *DockerSuite) TestEventsRename(c *check.C) {
746 746
 func (s *DockerSuite) TestEventsTop(c *check.C) {
747 747
 	since := daemonTime(c).Unix()
748 748
 
749
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
750
-	out, _, err := runCommandWithOutput(runCmd)
751
-	if err != nil {
752
-		c.Fatalf("Couldn't run true: %s\n%q", out, err)
753
-	}
749
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
754 750
 	cID := strings.TrimSpace(out)
755 751
 	c.Assert(waitRun(cID), check.IsNil)
756 752
 
757
-	cmd := exec.Command(dockerBinary, "top", cID)
758
-	out, _, err = runCommandWithOutput(cmd)
759
-	if err != nil {
760
-		c.Fatalf("Couldn't run docker top: %s\n%q", out, err)
761
-	}
762
-
763
-	cmd = exec.Command(dockerBinary, "stop", cID)
764
-	out, _, err = runCommandWithOutput(cmd)
765
-	if err != nil {
766
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
767
-	}
768
-
769
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
770
-	out, _, err = runCommandWithOutput(cmd)
771
-	if err != nil {
772
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
773
-	}
753
+	dockerCmd(c, "top", cID)
754
+	dockerCmd(c, "stop", cID)
774 755
 
756
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
775 757
 	if !strings.Contains(out, " top\n") {
776 758
 		c.Fatalf("Missing 'top' log event\n%s", out)
777 759
 	}
... ...
@@ -790,9 +632,7 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
790 790
 	since := daemonTime(c).Unix()
791 791
 	repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL)
792 792
 
793
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
794
-	out, _, err := runCommandWithOutput(runCmd)
795
-	c.Assert(err, check.IsNil)
793
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
796 794
 	cID := strings.TrimSpace(out)
797 795
 	c.Assert(waitRun(cID), check.IsNil)
798 796
 
... ...
@@ -800,10 +640,7 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
800 800
 	dockerCmd(c, "stop", cID)
801 801
 	dockerCmd(c, "push", repoName)
802 802
 
803
-	cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
804
-	out, _, err = runCommandWithOutput(cmd)
805
-	c.Assert(err, check.IsNil)
806
-
803
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
807 804
 	if !strings.Contains(out, repoName+": push\n") {
808 805
 		c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out)
809 806
 	}
... ...
@@ -19,32 +19,18 @@ import (
19 19
 )
20 20
 
21 21
 func (s *DockerSuite) TestExec(c *check.C) {
22
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
22 23
 
23
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
24
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
25
-		c.Fatal(out, err)
26
-	}
27
-
28
-	execCmd := exec.Command(dockerBinary, "exec", "testing", "cat", "/tmp/file")
29
-	out, _, err := runCommandWithOutput(execCmd)
30
-	if err != nil {
31
-		c.Fatal(out, err)
32
-	}
33
-
24
+	out, _ := dockerCmd(c, "exec", "testing", "cat", "/tmp/file")
34 25
 	out = strings.Trim(out, "\r\n")
35
-
36
-	if expected := "test"; out != expected {
37
-		c.Errorf("container exec should've printed %q but printed %q", expected, out)
26
+	if out != "test" {
27
+		c.Errorf("container exec should've printed test but printed %q", out)
38 28
 	}
39 29
 
40 30
 }
41 31
 
42 32
 func (s *DockerSuite) TestExecInteractive(c *check.C) {
43
-
44
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
45
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
46
-		c.Fatal(out, err)
47
-	}
33
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
48 34
 
49 35
 	execCmd := exec.Command(dockerBinary, "exec", "-i", "testing", "sh")
50 36
 	stdin, err := execCmd.StdinPipe()
... ...
@@ -90,31 +76,15 @@ func (s *DockerSuite) TestExecInteractive(c *check.C) {
90 90
 }
91 91
 
92 92
 func (s *DockerSuite) TestExecAfterContainerRestart(c *check.C) {
93
-
94
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
95
-	out, _, err := runCommandWithOutput(runCmd)
96
-	if err != nil {
97
-		c.Fatal(out, err)
98
-	}
99
-
93
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
100 94
 	cleanedContainerID := strings.TrimSpace(out)
95
+	dockerCmd(c, "restart", cleanedContainerID)
101 96
 
102
-	runCmd = exec.Command(dockerBinary, "restart", cleanedContainerID)
103
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
104
-		c.Fatal(out, err)
105
-	}
106
-
107
-	runCmd = exec.Command(dockerBinary, "exec", cleanedContainerID, "echo", "hello")
108
-	out, _, err = runCommandWithOutput(runCmd)
109
-	if err != nil {
110
-		c.Fatal(out, err)
111
-	}
112
-
97
+	out, _ = dockerCmd(c, "exec", cleanedContainerID, "echo", "hello")
113 98
 	outStr := strings.TrimSpace(out)
114 99
 	if outStr != "hello" {
115 100
 		c.Errorf("container should've printed hello, instead printed %q", outStr)
116 101
 	}
117
-
118 102
 }
119 103
 
120 104
 func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) {
... ...
@@ -149,65 +119,36 @@ func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) {
149 149
 
150 150
 // Regression test for #9155, #9044
151 151
 func (s *DockerSuite) TestExecEnv(c *check.C) {
152
-
153
-	runCmd := exec.Command(dockerBinary, "run",
154
-		"-e", "LALA=value1",
155
-		"-e", "LALA=value2",
152
+	dockerCmd(c, "run", "-e", "LALA=value1", "-e", "LALA=value2",
156 153
 		"-d", "--name", "testing", "busybox", "top")
157
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
158
-		c.Fatal(out, err)
159
-	}
160
-
161
-	execCmd := exec.Command(dockerBinary, "exec", "testing", "env")
162
-	out, _, err := runCommandWithOutput(execCmd)
163
-	if err != nil {
164
-		c.Fatal(out, err)
165
-	}
166 154
 
155
+	out, _ := dockerCmd(c, "exec", "testing", "env")
167 156
 	if strings.Contains(out, "LALA=value1") ||
168 157
 		!strings.Contains(out, "LALA=value2") ||
169 158
 		!strings.Contains(out, "HOME=/root") {
170 159
 		c.Errorf("exec env(%q), expect %q, %q", out, "LALA=value2", "HOME=/root")
171 160
 	}
172
-
173 161
 }
174 162
 
175 163
 func (s *DockerSuite) TestExecExitStatus(c *check.C) {
176
-
177
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
178
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
179
-		c.Fatal(out, err)
180
-	}
164
+	dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
181 165
 
182 166
 	// Test normal (non-detached) case first
183 167
 	cmd := exec.Command(dockerBinary, "exec", "top", "sh", "-c", "exit 23")
184 168
 	ec, _ := runCommand(cmd)
185
-
186 169
 	if ec != 23 {
187 170
 		c.Fatalf("Should have had an ExitCode of 23, not: %d", ec)
188 171
 	}
189
-
190 172
 }
191 173
 
192 174
 func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
193 175
 	defer unpauseAllContainers()
194 176
 
195
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
196
-	out, _, err := runCommandWithOutput(runCmd)
197
-	if err != nil {
198
-		c.Fatal(out, err)
199
-	}
200
-
177
+	out, _ := dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
201 178
 	ContainerID := strings.TrimSpace(out)
202 179
 
203
-	pausedCmd := exec.Command(dockerBinary, "pause", "testing")
204
-	out, _, _, err = runCommandWithStdoutStderr(pausedCmd)
205
-	if err != nil {
206
-		c.Fatal(out, err)
207
-	}
208
-
209
-	execCmd := exec.Command(dockerBinary, "exec", "-i", "-t", ContainerID, "echo", "hello")
210
-	out, _, err = runCommandWithOutput(execCmd)
180
+	dockerCmd(c, "pause", "testing")
181
+	out, _, err := dockerCmdWithError(c, "exec", "-i", "-t", ContainerID, "echo", "hello")
211 182
 	if err == nil {
212 183
 		c.Fatal("container should fail to exec new command if it is paused")
213 184
 	}
... ...
@@ -216,18 +157,13 @@ func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
216 216
 	if !strings.Contains(out, expected) {
217 217
 		c.Fatal("container should not exec new command if it is paused")
218 218
 	}
219
-
220 219
 }
221 220
 
222 221
 // regression test for #9476
223 222
 func (s *DockerSuite) TestExecTtyCloseStdin(c *check.C) {
223
+	dockerCmd(c, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
224 224
 
225
-	cmd := exec.Command(dockerBinary, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
226
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
227
-		c.Fatal(out, err)
228
-	}
229
-
230
-	cmd = exec.Command(dockerBinary, "exec", "-i", "exec_tty_stdin", "cat")
225
+	cmd := exec.Command(dockerBinary, "exec", "-i", "exec_tty_stdin", "cat")
231 226
 	stdinRw, err := cmd.StdinPipe()
232 227
 	if err != nil {
233 228
 		c.Fatal(err)
... ...
@@ -240,42 +176,22 @@ func (s *DockerSuite) TestExecTtyCloseStdin(c *check.C) {
240 240
 		c.Fatal(out, err)
241 241
 	}
242 242
 
243
-	cmd = exec.Command(dockerBinary, "top", "exec_tty_stdin")
244
-	out, _, err := runCommandWithOutput(cmd)
245
-	if err != nil {
246
-		c.Fatal(out, err)
247
-	}
248
-
243
+	out, _ := dockerCmd(c, "top", "exec_tty_stdin")
249 244
 	outArr := strings.Split(out, "\n")
250 245
 	if len(outArr) > 3 || strings.Contains(out, "nsenter-exec") {
251
-		// This is the really bad part
252
-		if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rm", "-f", "exec_tty_stdin")); err != nil {
253
-			c.Fatal(out, err)
254
-		}
255
-
256 246
 		c.Fatalf("exec process left running\n\t %s", out)
257 247
 	}
258
-
259 248
 }
260 249
 
261 250
 func (s *DockerSuite) TestExecTtyWithoutStdin(c *check.C) {
262
-
263
-	cmd := exec.Command(dockerBinary, "run", "-d", "-ti", "busybox")
264
-	out, _, err := runCommandWithOutput(cmd)
265
-	if err != nil {
266
-		c.Fatalf("failed to start container: %v (%v)", out, err)
267
-	}
268
-
251
+	out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
269 252
 	id := strings.TrimSpace(out)
270 253
 	if err := waitRun(id); err != nil {
271 254
 		c.Fatal(err)
272 255
 	}
273 256
 
274 257
 	defer func() {
275
-		cmd := exec.Command(dockerBinary, "kill", id)
276
-		if out, _, err := runCommandWithOutput(cmd); err != nil {
277
-			c.Fatalf("failed to kill container: %v (%v)", out, err)
278
-		}
258
+		dockerCmd(c, "kill", id)
279 259
 	}()
280 260
 
281 261
 	errChan := make(chan error)
... ...
@@ -304,15 +220,10 @@ func (s *DockerSuite) TestExecTtyWithoutStdin(c *check.C) {
304 304
 	case <-time.After(3 * time.Second):
305 305
 		c.Fatal("exec is running but should have failed")
306 306
 	}
307
-
308 307
 }
309 308
 
310 309
 func (s *DockerSuite) TestExecParseError(c *check.C) {
311
-
312
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
313
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
314
-		c.Fatal(out, err)
315
-	}
310
+	dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
316 311
 
317 312
 	// Test normal (non-detached) case first
318 313
 	cmd := exec.Command(dockerBinary, "exec", "top")
... ...
@@ -322,10 +233,7 @@ func (s *DockerSuite) TestExecParseError(c *check.C) {
322 322
 }
323 323
 
324 324
 func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
325
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
326
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
327
-		c.Fatal(out, err)
328
-	}
325
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
329 326
 
330 327
 	if err := exec.Command(dockerBinary, "exec", "testing", "top").Start(); err != nil {
331 328
 		c.Fatal(err)
... ...
@@ -351,20 +259,10 @@ func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
351 351
 }
352 352
 
353 353
 func (s *DockerSuite) TestExecCgroup(c *check.C) {
354
-	var cmd *exec.Cmd
355
-
356
-	cmd = exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
357
-	_, err := runCommand(cmd)
358
-	if err != nil {
359
-		c.Fatal(err)
360
-	}
354
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
361 355
 
362
-	cmd = exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/1/cgroup")
363
-	out, _, err := runCommandWithOutput(cmd)
364
-	if err != nil {
365
-		c.Fatal(out, err)
366
-	}
367
-	containerCgroups := sort.StringSlice(strings.Split(string(out), "\n"))
356
+	out, _ := dockerCmd(c, "exec", "testing", "cat", "/proc/1/cgroup")
357
+	containerCgroups := sort.StringSlice(strings.Split(out, "\n"))
368 358
 
369 359
 	var wg sync.WaitGroup
370 360
 	var mu sync.Mutex
... ...
@@ -374,13 +272,12 @@ func (s *DockerSuite) TestExecCgroup(c *check.C) {
374 374
 	for i := 0; i < 5; i++ {
375 375
 		wg.Add(1)
376 376
 		go func() {
377
-			cmd := exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/self/cgroup")
378
-			out, _, err := runCommandWithOutput(cmd)
377
+			out, _, err := dockerCmdWithError(c, "exec", "testing", "cat", "/proc/self/cgroup")
379 378
 			if err != nil {
380 379
 				errChan <- err
381 380
 				return
382 381
 			}
383
-			cg := sort.StringSlice(strings.Split(string(out), "\n"))
382
+			cg := sort.StringSlice(strings.Split(out, "\n"))
384 383
 
385 384
 			mu.Lock()
386 385
 			execCgroups = append(execCgroups, cg)
... ...
@@ -409,18 +306,13 @@ func (s *DockerSuite) TestExecCgroup(c *check.C) {
409 409
 			c.Fatal("cgroups mismatched")
410 410
 		}
411 411
 	}
412
-
413 412
 }
414 413
 
415 414
 func (s *DockerSuite) TestInspectExecID(c *check.C) {
416
-
417
-	out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top"))
418
-	if exitCode != 0 || err != nil {
419
-		c.Fatalf("failed to run container: %s, %v", out, err)
420
-	}
415
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
421 416
 	id := strings.TrimSuffix(out, "\n")
422 417
 
423
-	out, err = inspectField(id, "ExecIDs")
418
+	out, err := inspectField(id, "ExecIDs")
424 419
 	if err != nil {
425 420
 		c.Fatalf("failed to inspect container: %s, %v", out, err)
426 421
 	}
... ...
@@ -496,29 +388,15 @@ func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) {
496 496
 		c.Fatal(out, "id should not be nil")
497 497
 	}
498 498
 
499
-	execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
500
-	out, _, err := runCommandWithOutput(execCmd)
501
-	if err != nil {
502
-		c.Fatal(out, err)
503
-	}
504
-
499
+	dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
505 500
 	dockerCmd(c, "rename", "container1", "container_new")
506
-
507
-	execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
508
-	out, _, err = runCommandWithOutput(execCmd)
509
-	if err != nil {
510
-		c.Fatal(out, err)
511
-	}
512
-
501
+	dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
513 502
 }
514 503
 
515 504
 func (s *DockerSuite) TestRunExecDir(c *check.C) {
516 505
 	testRequires(c, SameHostDaemon)
517
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
518
-	out, _, err := runCommandWithOutput(cmd)
519
-	if err != nil {
520
-		c.Fatal(err, out)
521
-	}
506
+
507
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
522 508
 	id := strings.TrimSpace(out)
523 509
 	execDir := filepath.Join(execDriverPath, id)
524 510
 	stateFile := filepath.Join(execDir, "state.json")
... ...
@@ -537,11 +415,7 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
537 537
 		}
538 538
 	}
539 539
 
540
-	stopCmd := exec.Command(dockerBinary, "stop", id)
541
-	out, _, err = runCommandWithOutput(stopCmd)
542
-	if err != nil {
543
-		c.Fatal(err, out)
544
-	}
540
+	dockerCmd(c, "stop", id)
545 541
 	{
546 542
 		_, err := os.Stat(execDir)
547 543
 		if err == nil {
... ...
@@ -554,11 +428,7 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
554 554
 			c.Fatalf("Error should be about non-existing, got %s", err)
555 555
 		}
556 556
 	}
557
-	startCmd := exec.Command(dockerBinary, "start", id)
558
-	out, _, err = runCommandWithOutput(startCmd)
559
-	if err != nil {
560
-		c.Fatal(err, out)
561
-	}
557
+	dockerCmd(c, "start", id)
562 558
 	{
563 559
 		fi, err := os.Stat(execDir)
564 560
 		if err != nil {
... ...
@@ -572,11 +442,7 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
572 572
 			c.Fatal(err)
573 573
 		}
574 574
 	}
575
-	rmCmd := exec.Command(dockerBinary, "rm", "-f", id)
576
-	out, _, err = runCommandWithOutput(rmCmd)
577
-	if err != nil {
578
-		c.Fatal(err, out)
579
-	}
575
+	dockerCmd(c, "rm", "-f", id)
580 576
 	{
581 577
 		_, err := os.Stat(execDir)
582 578
 		if err == nil {
... ...
@@ -589,7 +455,6 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
589 589
 			c.Fatalf("Error should be about non-existing, got %s", err)
590 590
 		}
591 591
 	}
592
-
593 592
 }
594 593
 
595 594
 func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
... ...
@@ -607,13 +472,8 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
607 607
 			c.Fatal("Content was not what was modified in the container", string(content))
608 608
 		}
609 609
 
610
-		out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "top"))
611
-		if err != nil {
612
-			c.Fatal(err)
613
-		}
614
-
610
+		out, _ := dockerCmd(c, "run", "-d", "--name", "c2", "busybox", "top")
615 611
 		contID := strings.TrimSpace(out)
616
-
617 612
 		netFilePath := containerStorageFile(contID, fn)
618 613
 
619 614
 		f, err := os.OpenFile(netFilePath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644)
... ...
@@ -637,40 +497,25 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
637 637
 		}
638 638
 		f.Close()
639 639
 
640
-		res, err := exec.Command(dockerBinary, "exec", contID, "cat", "/etc/"+fn).CombinedOutput()
641
-		if err != nil {
642
-			c.Fatalf("Output: %s, error: %s", res, err)
643
-		}
644
-		if string(res) != "success2\n" {
640
+		res, _ := dockerCmd(c, "exec", contID, "cat", "/etc/"+fn)
641
+		if res != "success2\n" {
645 642
 			c.Fatalf("Expected content of %s: %q, got: %q", fn, "success2\n", res)
646 643
 		}
647 644
 	}
648 645
 }
649 646
 
650 647
 func (s *DockerSuite) TestExecWithUser(c *check.C) {
651
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top")
652
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
653
-		c.Fatal(out, err)
654
-	}
648
+	dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
655 649
 
656
-	cmd := exec.Command(dockerBinary, "exec", "-u", "1", "parent", "id")
657
-	out, _, err := runCommandWithOutput(cmd)
658
-	if err != nil {
659
-		c.Fatal(err, out)
660
-	}
650
+	out, _ := dockerCmd(c, "exec", "-u", "1", "parent", "id")
661 651
 	if !strings.Contains(out, "uid=1(daemon) gid=1(daemon)") {
662 652
 		c.Fatalf("exec with user by id expected daemon user got %s", out)
663 653
 	}
664 654
 
665
-	cmd = exec.Command(dockerBinary, "exec", "-u", "root", "parent", "id")
666
-	out, _, err = runCommandWithOutput(cmd)
667
-	if err != nil {
668
-		c.Fatal(err, out)
669
-	}
655
+	out, _ = dockerCmd(c, "exec", "-u", "root", "parent", "id")
670 656
 	if !strings.Contains(out, "uid=0(root) gid=0(root)") {
671 657
 		c.Fatalf("exec with user by root expected root user got %s", out)
672 658
 	}
673
-
674 659
 }
675 660
 
676 661
 func (s *DockerSuite) TestExecWithImageUser(c *check.C) {
... ...
@@ -15,10 +15,7 @@ import (
15 15
 
16 16
 // regression test for #12546
17 17
 func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
18
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "busybox", "/bin/cat"))
19
-	if err != nil {
20
-		c.Fatal(err)
21
-	}
18
+	out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
22 19
 	contId := strings.TrimSpace(out)
23 20
 
24 21
 	cmd := exec.Command(dockerBinary, "exec", "-i", contId, "echo", "-n", "hello")
... ...
@@ -3,27 +3,21 @@
3 3
 package main
4 4
 
5 5
 import (
6
-	"os/exec"
7 6
 	"strings"
8 7
 
9 8
 	"github.com/go-check/check"
10 9
 )
11 10
 
12 11
 func (s *DockerSuite) TestExperimentalVersion(c *check.C) {
13
-	versionCmd := exec.Command(dockerBinary, "version")
14
-	out, _, err := runCommandWithOutput(versionCmd)
15
-	if err != nil {
16
-		c.Fatalf("failed to execute docker version: %s, %v", out, err)
17
-	}
18
-
12
+	out, _ := dockerCmd(c, "version")
19 13
 	for _, line := range strings.Split(out, "\n") {
20 14
 		if strings.HasPrefix(line, "Experimental (client):") || strings.HasPrefix(line, "Experimental (server):") {
21 15
 			c.Assert(line, check.Matches, "*true")
22 16
 		}
23 17
 	}
24 18
 
25
-	versionCmd = exec.Command(dockerBinary, "-v")
26
-	if out, _, err = runCommandWithOutput(versionCmd); err != nil || !strings.Contains(out, ", experimental") {
27
-		c.Fatalf("docker version did not contain experimental: %s, %v", out, err)
19
+	out, _ = dockerCmd(c, "-v")
20
+	if !strings.Contains(out, ", experimental") {
21
+		c.Fatalf("docker version did not contain experimental: %s", out)
28 22
 	}
29 23
 }
... ...
@@ -12,20 +12,13 @@ import (
12 12
 func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
13 13
 	containerID := "testexportcontainerandimportimage"
14 14
 
15
-	runCmd := exec.Command(dockerBinary, "run", "--name", containerID, "busybox", "true")
16
-	out, _, err := runCommandWithOutput(runCmd)
17
-	if err != nil {
18
-		c.Fatal("failed to create a container", out, err)
19
-	}
15
+	dockerCmd(c, "run", "--name", containerID, "busybox", "true")
20 16
 
21
-	exportCmd := exec.Command(dockerBinary, "export", containerID)
22
-	if out, _, err = runCommandWithOutput(exportCmd); err != nil {
23
-		c.Fatalf("failed to export container: %s, %v", out, err)
24
-	}
17
+	out, _ := dockerCmd(c, "export", containerID)
25 18
 
26 19
 	importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
27 20
 	importCmd.Stdin = strings.NewReader(out)
28
-	out, _, err = runCommandWithOutput(importCmd)
21
+	out, _, err := runCommandWithOutput(importCmd)
29 22
 	if err != nil {
30 23
 		c.Fatalf("failed to import image: %s, %v", out, err)
31 24
 	}
... ...
@@ -40,20 +33,11 @@ func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
40 40
 func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
41 41
 	containerID := "testexportcontainerwithoutputandimportimage"
42 42
 
43
-	runCmd := exec.Command(dockerBinary, "run", "--name", containerID, "busybox", "true")
44
-	out, _, err := runCommandWithOutput(runCmd)
45
-	if err != nil {
46
-		c.Fatal("failed to create a container", out, err)
47
-	}
48
-
43
+	dockerCmd(c, "run", "--name", containerID, "busybox", "true")
44
+	dockerCmd(c, "export", "--output=testexp.tar", containerID)
49 45
 	defer os.Remove("testexp.tar")
50 46
 
51
-	exportCmd := exec.Command(dockerBinary, "export", "--output=testexp.tar", containerID)
52
-	if out, _, err = runCommandWithOutput(exportCmd); err != nil {
53
-		c.Fatalf("failed to export container: %s, %v", out, err)
54
-	}
55
-
56
-	out, _, err = runCommandWithOutput(exec.Command("cat", "testexp.tar"))
47
+	out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar"))
57 48
 	if err != nil {
58 49
 		c.Fatal(out, err)
59 50
 	}
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"regexp"
7 6
 	"strconv"
8 7
 	"strings"
... ...
@@ -47,11 +46,7 @@ RUN echo "Z"`,
47 47
 		c.Fatal(err)
48 48
 	}
49 49
 
50
-	out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "history", "testbuildhistory"))
51
-	if err != nil || exitCode != 0 {
52
-		c.Fatalf("failed to get image history: %s, %v", out, err)
53
-	}
54
-
50
+	out, _ := dockerCmd(c, "history", "testbuildhistory")
55 51
 	actualValues := strings.Split(out, "\n")[1:27]
56 52
 	expectedValues := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"}
57 53
 
... ...
@@ -67,18 +62,13 @@ RUN echo "Z"`,
67 67
 }
68 68
 
69 69
 func (s *DockerSuite) TestHistoryExistentImage(c *check.C) {
70
-	historyCmd := exec.Command(dockerBinary, "history", "busybox")
71
-	_, exitCode, err := runCommandWithOutput(historyCmd)
72
-	if err != nil || exitCode != 0 {
73
-		c.Fatal("failed to get image history")
74
-	}
70
+	dockerCmd(c, "history", "busybox")
75 71
 }
76 72
 
77 73
 func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) {
78
-	historyCmd := exec.Command(dockerBinary, "history", "testHistoryNonExistentImage")
79
-	_, exitCode, err := runCommandWithOutput(historyCmd)
80
-	if err == nil || exitCode == 0 {
81
-		c.Fatal("history on a non-existent image didn't result in a non-zero exit status")
74
+	_, _, err := dockerCmdWithError(c, "history", "testHistoryNonExistentImage")
75
+	if err == nil {
76
+		c.Fatal("history on a non-existent image should fail.")
82 77
 	}
83 78
 }
84 79
 
... ...
@@ -86,44 +76,26 @@ func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
86 86
 	name := "testhistoryimagewithcomment"
87 87
 
88 88
 	// make a image through docker commit <container id> [ -m messages ]
89
-	//runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
90
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
91
-	out, _, err := runCommandWithOutput(runCmd)
92
-	if err != nil {
93
-		c.Fatalf("failed to run container: %s, %v", out, err)
94
-	}
95 89
 
96
-	waitCmd := exec.Command(dockerBinary, "wait", name)
97
-	if out, _, err := runCommandWithOutput(waitCmd); err != nil {
98
-		c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
99
-	}
90
+	dockerCmd(c, "run", "--name", name, "busybox", "true")
91
+	dockerCmd(c, "wait", name)
100 92
 
101 93
 	comment := "This_is_a_comment"
102
-
103
-	commitCmd := exec.Command(dockerBinary, "commit", "-m="+comment, name, name)
104
-	if out, _, err := runCommandWithOutput(commitCmd); err != nil {
105
-		c.Fatalf("failed to commit container to image: %s, %v", out, err)
106
-	}
94
+	dockerCmd(c, "commit", "-m="+comment, name, name)
107 95
 
108 96
 	// test docker history <image id> to check comment messages
109
-	historyCmd := exec.Command(dockerBinary, "history", name)
110
-	out, exitCode, err := runCommandWithOutput(historyCmd)
111
-	if err != nil || exitCode != 0 {
112
-		c.Fatalf("failed to get image history: %s, %v", out, err)
113
-	}
114 97
 
98
+	out, _ := dockerCmd(c, "history", name)
115 99
 	outputTabs := strings.Fields(strings.Split(out, "\n")[1])
116
-	//outputTabs := regexp.MustCompile("  +").Split(outputLine, -1)
117 100
 	actualValue := outputTabs[len(outputTabs)-1]
118 101
 
119 102
 	if !strings.Contains(actualValue, comment) {
120 103
 		c.Fatalf("Expected comments %q, but found %q", comment, actualValue)
121 104
 	}
122
-
123 105
 }
124 106
 
125 107
 func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
126
-	out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "history", "--human=false", "busybox"))
108
+	out, _ := dockerCmd(c, "history", "--human=false", "busybox")
127 109
 	lines := strings.Split(out, "\n")
128 110
 	sizeColumnRegex, _ := regexp.Compile("SIZE +")
129 111
 	indices := sizeColumnRegex.FindStringIndex(lines[0])
... ...
@@ -141,7 +113,7 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
141 141
 }
142 142
 
143 143
 func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) {
144
-	out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "history", "--human=true", "busybox"))
144
+	out, _ := dockerCmd(c, "history", "--human=true", "busybox")
145 145
 	lines := strings.Split(out, "\n")
146 146
 	sizeColumnRegex, _ := regexp.Compile("SIZE +")
147 147
 	humanSizeRegex, _ := regexp.Compile("^\\d+.*B$") // Matches human sizes like 10 MB, 3.2 KB, etc
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"reflect"
7 6
 	"sort"
8 7
 	"strings"
... ...
@@ -13,16 +12,10 @@ import (
13 13
 )
14 14
 
15 15
 func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) {
16
-	imagesCmd := exec.Command(dockerBinary, "images")
17
-	out, _, err := runCommandWithOutput(imagesCmd)
18
-	if err != nil {
19
-		c.Fatalf("listing images failed with errors: %s, %v", out, err)
20
-	}
21
-
16
+	out, _ := dockerCmd(c, "images")
22 17
 	if !strings.Contains(out, "busybox") {
23 18
 		c.Fatal("images should've listed busybox")
24 19
 	}
25
-
26 20
 }
27 21
 
28 22
 func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
... ...
@@ -47,10 +40,7 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
47 47
 		c.Fatal(err)
48 48
 	}
49 49
 
50
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "images", "-q", "--no-trunc"))
51
-	if err != nil {
52
-		c.Fatalf("listing images failed with errors: %s, %v", out, err)
53
-	}
50
+	out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
54 51
 	imgs := strings.Split(out, "\n")
55 52
 	if imgs[0] != id3 {
56 53
 		c.Fatalf("First image must be %s, got %s", id3, imgs[0])
... ...
@@ -61,16 +51,13 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
61 61
 	if imgs[2] != id1 {
62 62
 		c.Fatalf("Third image must be %s, got %s", id1, imgs[2])
63 63
 	}
64
-
65 64
 }
66 65
 
67 66
 func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) {
68
-	imagesCmd := exec.Command(dockerBinary, "images", "-f", "FOO=123")
69
-	out, _, err := runCommandWithOutput(imagesCmd)
70
-	if !strings.Contains(out, "Invalid filter") {
71
-		c.Fatalf("error should occur when listing images with invalid filter name FOO, %s, %v", out, err)
67
+	out, _, err := dockerCmdWithError(c, "images", "-f", "FOO=123")
68
+	if err == nil || !strings.Contains(out, "Invalid filter") {
69
+		c.Fatalf("error should occur when listing images with invalid filter name FOO, %s", out)
72 70
 	}
73
-
74 71
 }
75 72
 
76 73
 func (s *DockerSuite) TestImagesFilterLabel(c *check.C) {
... ...
@@ -98,28 +85,17 @@ func (s *DockerSuite) TestImagesFilterLabel(c *check.C) {
98 98
 		c.Fatal(err)
99 99
 	}
100 100
 
101
-	cmd := exec.Command(dockerBinary, "images", "--no-trunc", "-q", "-f", "label=match")
102
-	out, _, err := runCommandWithOutput(cmd)
103
-	if err != nil {
104
-		c.Fatal(out, err)
105
-	}
101
+	out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
106 102
 	out = strings.TrimSpace(out)
107
-
108 103
 	if (!strings.Contains(out, image1ID) && !strings.Contains(out, image2ID)) || strings.Contains(out, image3ID) {
109 104
 		c.Fatalf("Expected ids %s,%s got %s", image1ID, image2ID, out)
110 105
 	}
111 106
 
112
-	cmd = exec.Command(dockerBinary, "images", "--no-trunc", "-q", "-f", "label=match=me too")
113
-	out, _, err = runCommandWithOutput(cmd)
114
-	if err != nil {
115
-		c.Fatal(out, err)
116
-	}
107
+	out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too")
117 108
 	out = strings.TrimSpace(out)
118
-
119 109
 	if out != image2ID {
120 110
 		c.Fatalf("Expected %s got %s", image2ID, out)
121 111
 	}
122
-
123 112
 }
124 113
 
125 114
 func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
... ...
@@ -140,11 +116,7 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
140 140
 
141 141
 	imageListings := make([][]string, 5, 5)
142 142
 	for idx, filter := range filters {
143
-		cmd := exec.Command(dockerBinary, "images", "-q", "-f", filter)
144
-		out, _, err := runCommandWithOutput(cmd)
145
-		if err != nil {
146
-			c.Fatal(err)
147
-		}
143
+		out, _ := dockerCmd(c, "images", "-q", "-f", filter)
148 144
 		listing := strings.Split(out, "\n")
149 145
 		sort.Strings(listing)
150 146
 		imageListings[idx] = listing
... ...
@@ -162,42 +134,22 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
162 162
 			c.Fatalf("All output must be the same")
163 163
 		}
164 164
 	}
165
-
166 165
 }
167 166
 
168 167
 func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
169
-
170 168
 	// create container 1
171
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
172
-	out, _, err := runCommandWithOutput(cmd)
173
-	if err != nil {
174
-		c.Fatalf("error running busybox: %s, %v", out, err)
175
-	}
169
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
176 170
 	containerId1 := strings.TrimSpace(out)
177 171
 
178 172
 	// tag as foobox
179
-	cmd = exec.Command(dockerBinary, "commit", containerId1, "foobox")
180
-	out, _, err = runCommandWithOutput(cmd)
181
-	if err != nil {
182
-		c.Fatalf("error tagging foobox: %s", err)
183
-	}
173
+	out, _ = dockerCmd(c, "commit", containerId1, "foobox")
184 174
 	imageId := stringid.TruncateID(strings.TrimSpace(out))
185 175
 
186 176
 	// overwrite the tag, making the previous image dangling
187
-	cmd = exec.Command(dockerBinary, "tag", "-f", "busybox", "foobox")
188
-	out, _, err = runCommandWithOutput(cmd)
189
-	if err != nil {
190
-		c.Fatalf("error tagging foobox: %s", err)
191
-	}
192
-
193
-	cmd = exec.Command(dockerBinary, "images", "-q", "-f", "dangling=true")
194
-	out, _, err = runCommandWithOutput(cmd)
195
-	if err != nil {
196
-		c.Fatalf("listing images failed with errors: %s, %v", out, err)
197
-	}
177
+	dockerCmd(c, "tag", "-f", "busybox", "foobox")
198 178
 
179
+	out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
199 180
 	if e, a := 1, strings.Count(out, imageId); e != a {
200 181
 		c.Fatalf("expected 1 dangling image, got %d: %s", a, out)
201 182
 	}
202
-
203 183
 }
... ...
@@ -11,14 +11,10 @@ import (
11 11
 )
12 12
 
13 13
 func (s *DockerSuite) TestImportDisplay(c *check.C) {
14
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
15
-	out, _, err := runCommandWithOutput(runCmd)
16
-	if err != nil {
17
-		c.Fatal("failed to create a container", out, err)
18
-	}
14
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
19 15
 	cleanedContainerID := strings.TrimSpace(out)
20 16
 
21
-	out, _, err = runCommandPipelineWithOutput(
17
+	out, _, err := runCommandPipelineWithOutput(
22 18
 		exec.Command(dockerBinary, "export", cleanedContainerID),
23 19
 		exec.Command(dockerBinary, "import", "-"),
24 20
 	)
... ...
@@ -31,21 +27,14 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
31 31
 	}
32 32
 	image := strings.TrimSpace(out)
33 33
 
34
-	runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
35
-	out, _, err = runCommandWithOutput(runCmd)
36
-	if err != nil {
37
-		c.Fatal("failed to create a container", out, err)
38
-	}
39
-
34
+	out, _ = dockerCmd(c, "run", "--rm", image, "true")
40 35
 	if out != "" {
41 36
 		c.Fatalf("command output should've been nothing, was %q", out)
42 37
 	}
43
-
44 38
 }
45 39
 
46 40
 func (s *DockerSuite) TestImportBadURL(c *check.C) {
47
-	runCmd := exec.Command(dockerBinary, "import", "http://nourl/bad")
48
-	out, _, err := runCommandWithOutput(runCmd)
41
+	out, _, err := dockerCmdWithError(c, "import", "http://nourl/bad")
49 42
 	if err == nil {
50 43
 		c.Fatal("import was supposed to fail but didn't")
51 44
 	}
... ...
@@ -55,11 +44,7 @@ func (s *DockerSuite) TestImportBadURL(c *check.C) {
55 55
 }
56 56
 
57 57
 func (s *DockerSuite) TestImportFile(c *check.C) {
58
-	runCmd := exec.Command(dockerBinary, "run", "--name", "test-import", "busybox", "true")
59
-	out, _, err := runCommandWithOutput(runCmd)
60
-	if err != nil {
61
-		c.Fatal("failed to create a container", out, err)
62
-	}
58
+	dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
63 59
 
64 60
 	temporaryFile, err := ioutil.TempFile("", "exportImportTest")
65 61
 	if err != nil {
... ...
@@ -67,42 +52,29 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
67 67
 	}
68 68
 	defer os.Remove(temporaryFile.Name())
69 69
 
70
-	runCmd = exec.Command(dockerBinary, "export", "test-import")
70
+	runCmd := exec.Command(dockerBinary, "export", "test-import")
71 71
 	runCmd.Stdout = bufio.NewWriter(temporaryFile)
72 72
 
73 73
 	_, err = runCommand(runCmd)
74 74
 	if err != nil {
75
-		c.Fatal("failed to export a container", out, err)
76
-	}
77
-
78
-	runCmd = exec.Command(dockerBinary, "import", temporaryFile.Name())
79
-	out, _, err = runCommandWithOutput(runCmd)
80
-	if err != nil {
81
-		c.Fatal("failed to import a container", out, err)
75
+		c.Fatal("failed to export a container", err)
82 76
 	}
83 77
 
78
+	out, _ := dockerCmd(c, "import", temporaryFile.Name())
84 79
 	if n := strings.Count(out, "\n"); n != 1 {
85 80
 		c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
86 81
 	}
87 82
 	image := strings.TrimSpace(out)
88 83
 
89
-	runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
90
-	out, _, err = runCommandWithOutput(runCmd)
91
-	if err != nil {
92
-		c.Fatal("failed to create a container", out, err)
93
-	}
94
-
84
+	out, _ = dockerCmd(c, "run", "--rm", image, "true")
95 85
 	if out != "" {
96 86
 		c.Fatalf("command output should've been nothing, was %q", out)
97 87
 	}
98
-
99 88
 }
100 89
 
101 90
 func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
102
-	runCmd := exec.Command(dockerBinary, "import", "example.com/myImage.tar")
103
-	_, exitCode, err := runCommandWithOutput(runCmd)
91
+	_, exitCode, err := dockerCmdWithError(c, "import", "example.com/myImage.tar")
104 92
 	if exitCode == 0 || err == nil {
105 93
 		c.Fatalf("import non-existing file must failed")
106 94
 	}
107
-
108 95
 }
... ...
@@ -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/utils"
... ...
@@ -10,11 +9,7 @@ import (
10 10
 
11 11
 // ensure docker info succeeds
12 12
 func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
13
-	versionCmd := exec.Command(dockerBinary, "info")
14
-	out, exitCode, err := runCommandWithOutput(versionCmd)
15
-	if err != nil || exitCode != 0 {
16
-		c.Fatalf("failed to execute docker info: %s, %v", out, err)
17
-	}
13
+	out, _ := dockerCmd(c, "info")
18 14
 
19 15
 	// always shown fields
20 16
 	stringsToCheck := []string{
... ...
@@ -18,7 +18,6 @@ func (s *DockerSuite) TestInspectImage(c *check.C) {
18 18
 	if id != imageTestID {
19 19
 		c.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestID, imageTest, id)
20 20
 	}
21
-
22 21
 }
23 22
 
24 23
 func (s *DockerSuite) TestInspectInt64(c *check.C) {
... ...
@@ -27,7 +26,6 @@ func (s *DockerSuite) TestInspectInt64(c *check.C) {
27 27
 	if err != nil {
28 28
 		c.Fatalf("failed to run container: %v, output: %q", err, out)
29 29
 	}
30
-
31 30
 	out = strings.TrimSpace(out)
32 31
 
33 32
 	inspectOut, err := inspectField(out, "HostConfig.Memory")
... ...
@@ -43,18 +41,8 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) {
43 43
 	//Both the container and image are named busybox. docker inspect will fetch the container JSON.
44 44
 	//If the container JSON is not available, it will go for the image JSON.
45 45
 
46
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "true")
47
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
48
-	if err != nil {
49
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
50
-	}
51
-
52
-	inspectCmd := exec.Command(dockerBinary, "inspect", "busybox")
53
-
54
-	_, exitCode, err := runCommandWithOutput(inspectCmd)
55
-	if exitCode != 0 || err != nil {
56
-		c.Fatalf("failed to inspect container: %s, %v", out, err)
57
-	}
46
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
47
+	dockerCmd(c, "inspect", "busybox")
58 48
 }
59 49
 
60 50
 func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
... ...
@@ -62,16 +50,10 @@ func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
62 62
 	//Both the container and image are named busybox. docker inspect will fetch container
63 63
 	//JSON State.Running field. If the field is true, it's a container.
64 64
 
65
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "top")
66
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
67
-	if err != nil {
68
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
69
-	}
65
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
70 66
 
71 67
 	formatStr := fmt.Sprintf("--format='{{.State.Running}}'")
72
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=container", formatStr, "busybox")
73
-
74
-	out, exitCode, err := runCommandWithOutput(inspectCmd)
68
+	out, exitCode, err := dockerCmdWithError(c, "inspect", "--type=container", formatStr, "busybox")
75 69
 	if exitCode != 0 || err != nil {
76 70
 		c.Fatalf("failed to inspect container: %s, %v", out, err)
77 71
 	}
... ...
@@ -87,15 +69,9 @@ func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *check.C) {
87 87
 	//JSON. Since there is no container named busybox and --type=container, docker inspect will
88 88
 	//not try to get the image JSON. It will throw an error.
89 89
 
90
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
91
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
92
-	if err != nil {
93
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
94
-	}
95
-
96
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=container", "busybox")
90
+	dockerCmd(c, "run", "-d", "busybox", "true")
97 91
 
98
-	_, exitCode, err := runCommandWithOutput(inspectCmd)
92
+	_, exitCode, err := dockerCmdWithError(c, "inspect", "--type=container", "busybox")
99 93
 	if exitCode == 0 || err == nil {
100 94
 		c.Fatalf("docker inspect should have failed, as there is no container named busybox")
101 95
 	}
... ...
@@ -107,15 +83,9 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
107 107
 	//JSON as --type=image. if there is no image with name busybox, docker inspect
108 108
 	//will throw an error.
109 109
 
110
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "true")
111
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
112
-	if err != nil {
113
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
114
-	}
115
-
116
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=image", "busybox")
110
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
117 111
 
118
-	out, exitCode, err := runCommandWithOutput(inspectCmd)
112
+	out, exitCode, err := dockerCmdWithError(c, "inspect", "--type=image", "busybox")
119 113
 	if exitCode != 0 || err != nil {
120 114
 		c.Fatalf("failed to inspect image: %s, %v", out, err)
121 115
 	}
... ...
@@ -123,7 +93,6 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
123 123
 	if strings.Contains(out, "State") {
124 124
 		c.Fatal("not an image JSON")
125 125
 	}
126
-
127 126
 }
128 127
 
129 128
 func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
... ...
@@ -131,15 +100,9 @@ func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
131 131
 	//Both the container and image are named busybox. docker inspect will fail
132 132
 	//as --type=foobar is not a valid value for the flag.
133 133
 
134
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "true")
135
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
136
-	if err != nil {
137
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
138
-	}
139
-
140
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=foobar", "busybox")
134
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
141 135
 
142
-	out, exitCode, err := runCommandWithOutput(inspectCmd)
136
+	out, exitCode, err := dockerCmdWithError(c, "inspect", "--type=foobar", "busybox")
143 137
 	if exitCode != 0 || err != nil {
144 138
 		if !strings.Contains(out, "not a valid value for --type") {
145 139
 			c.Fatalf("failed to inspect image: %s, %v", out, err)
... ...
@@ -159,8 +122,7 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
159 159
 
160 160
 	//now see if the size turns out to be the same
161 161
 	formatStr := fmt.Sprintf("--format='{{eq .Size %d}}'", size)
162
-	imagesCmd := exec.Command(dockerBinary, "inspect", formatStr, imageTest)
163
-	out, exitCode, err := runCommandWithOutput(imagesCmd)
162
+	out, exitCode, err := dockerCmdWithError(c, "inspect", formatStr, imageTest)
164 163
 	if exitCode != 0 || err != nil {
165 164
 		c.Fatalf("failed to inspect image: %s, %v", out, err)
166 165
 	}
... ...
@@ -189,11 +151,7 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
189 189
 
190 190
 	//now get the exit code to verify
191 191
 	formatStr := fmt.Sprintf("--format='{{eq .State.ExitCode %d}}'", exitCode)
192
-	runCmd = exec.Command(dockerBinary, "inspect", formatStr, id)
193
-	out, _, err = runCommandWithOutput(runCmd)
194
-	if err != nil {
195
-		c.Fatalf("failed to inspect container: %s, %v", out, err)
196
-	}
192
+	out, _ = dockerCmd(c, "inspect", formatStr, id)
197 193
 	if result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")); err != nil || !result {
198 194
 		c.Fatalf("Expected exitcode: %d for container: %s", exitCode, id)
199 195
 	}
... ...
@@ -230,12 +188,7 @@ func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
230 230
 }
231 231
 
232 232
 func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
233
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
234
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
235
-	if err != nil {
236
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
237
-	}
238
-
233
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
239 234
 	out = strings.TrimSpace(out)
240 235
 
241 236
 	name, err := inspectField(out, "GraphDriver.Name")
... ...
@@ -1,75 +1,42 @@
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) TestKillContainer(c *check.C) {
11
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
12
-	out, _, err := runCommandWithOutput(runCmd)
13
-	if err != nil {
14
-		c.Fatal(out, err)
15
-	}
16
-
10
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
17 11
 	cleanedContainerID := strings.TrimSpace(out)
18 12
 	c.Assert(waitRun(cleanedContainerID), check.IsNil)
19 13
 
20
-	killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
21
-	if out, _, err = runCommandWithOutput(killCmd); err != nil {
22
-		c.Fatalf("failed to kill container: %s, %v", out, err)
23
-	}
24
-
25
-	listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q")
26
-	out, _, err = runCommandWithOutput(listRunningContainersCmd)
27
-	if err != nil {
28
-		c.Fatalf("failed to list running containers: %s, %v", out, err)
29
-	}
14
+	dockerCmd(c, "kill", cleanedContainerID)
30 15
 
16
+	out, _ = dockerCmd(c, "ps", "-q")
31 17
 	if strings.Contains(out, cleanedContainerID) {
32 18
 		c.Fatal("killed container is still running")
33 19
 	}
34 20
 }
35 21
 
36 22
 func (s *DockerSuite) TestKillofStoppedContainer(c *check.C) {
37
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
38
-	out, _, err := runCommandWithOutput(runCmd)
39
-	c.Assert(err, check.IsNil)
40
-
23
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
41 24
 	cleanedContainerID := strings.TrimSpace(out)
42 25
 
43
-	stopCmd := exec.Command(dockerBinary, "stop", cleanedContainerID)
44
-	out, _, err = runCommandWithOutput(stopCmd)
45
-	c.Assert(err, check.IsNil)
26
+	dockerCmd(c, "stop", cleanedContainerID)
46 27
 
47
-	killCmd := exec.Command(dockerBinary, "kill", "-s", "30", cleanedContainerID)
48
-	_, _, err = runCommandWithOutput(killCmd)
28
+	_, _, err := dockerCmdWithError(c, "kill", "-s", "30", cleanedContainerID)
49 29
 	c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID))
50 30
 }
51 31
 
52 32
 func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
53
-	runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top")
54
-	out, _, err := runCommandWithOutput(runCmd)
55
-	if err != nil {
56
-		c.Fatal(out, err)
57
-	}
58
-
33
+	out, _ := dockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top")
59 34
 	cleanedContainerID := strings.TrimSpace(out)
60 35
 	c.Assert(waitRun(cleanedContainerID), check.IsNil)
61 36
 
62
-	killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
63
-	if out, _, err = runCommandWithOutput(killCmd); err != nil {
64
-		c.Fatalf("failed to kill container: %s, %v", out, err)
65
-	}
66
-
67
-	listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q")
68
-	out, _, err = runCommandWithOutput(listRunningContainersCmd)
69
-	if err != nil {
70
-		c.Fatalf("failed to list running containers: %s, %v", out, err)
71
-	}
37
+	dockerCmd(c, "kill", cleanedContainerID)
72 38
 
39
+	out, _ = dockerCmd(c, "ps", "-q")
73 40
 	if strings.Contains(out, cleanedContainerID) {
74 41
 		c.Fatal("killed container is still running")
75 42
 	}
... ...
@@ -77,58 +44,45 @@ func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
77 77
 
78 78
 // regression test about correct signal parsing see #13665
79 79
 func (s *DockerSuite) TestKillWithSignal(c *check.C) {
80
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
81
-	out, _, err := runCommandWithOutput(runCmd)
82
-	c.Assert(err, check.IsNil)
83
-
80
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
84 81
 	cid := strings.TrimSpace(out)
85 82
 	c.Assert(waitRun(cid), check.IsNil)
86 83
 
87
-	killCmd := exec.Command(dockerBinary, "kill", "-s", "SIGWINCH", cid)
88
-	_, err = runCommand(killCmd)
89
-	c.Assert(err, check.IsNil)
84
+	dockerCmd(c, "kill", "-s", "SIGWINCH", cid)
90 85
 
91
-	running, err := inspectField(cid, "State.Running")
86
+	running, _ := inspectField(cid, "State.Running")
92 87
 	if running != "true" {
93 88
 		c.Fatal("Container should be in running state after SIGWINCH")
94 89
 	}
95 90
 }
96 91
 
97 92
 func (s *DockerSuite) TestKillWithInvalidSignal(c *check.C) {
98
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
99
-	out, _, err := runCommandWithOutput(runCmd)
100
-	c.Assert(err, check.IsNil)
101
-
93
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
102 94
 	cid := strings.TrimSpace(out)
103 95
 	c.Assert(waitRun(cid), check.IsNil)
104 96
 
105
-	killCmd := exec.Command(dockerBinary, "kill", "-s", "0", cid)
106
-	out, _, err = runCommandWithOutput(killCmd)
97
+	out, _, err := dockerCmdWithError(c, "kill", "-s", "0", cid)
107 98
 	c.Assert(err, check.NotNil)
108 99
 	if !strings.ContainsAny(out, "Invalid signal: 0") {
109 100
 		c.Fatal("Kill with an invalid signal didn't error out correctly")
110 101
 	}
111 102
 
112
-	running, err := inspectField(cid, "State.Running")
103
+	running, _ := inspectField(cid, "State.Running")
113 104
 	if running != "true" {
114 105
 		c.Fatal("Container should be in running state after an invalid signal")
115 106
 	}
116 107
 
117
-	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
118
-	out, _, err = runCommandWithOutput(runCmd)
119
-	c.Assert(err, check.IsNil)
120
-
108
+	out, _ = dockerCmd(c, "run", "-d", "busybox", "top")
121 109
 	cid = strings.TrimSpace(out)
122 110
 	c.Assert(waitRun(cid), check.IsNil)
123 111
 
124
-	killCmd = exec.Command(dockerBinary, "kill", "-s", "SIG42", cid)
125
-	out, _, err = runCommandWithOutput(killCmd)
112
+	out, _, err = dockerCmdWithError(c, "kill", "-s", "SIG42", cid)
126 113
 	c.Assert(err, check.NotNil)
127 114
 	if !strings.ContainsAny(out, "Invalid signal: SIG42") {
128 115
 		c.Fatal("Kill with an invalid signal error out correctly")
129 116
 	}
130 117
 
131
-	running, err = inspectField(cid, "State.Running")
118
+	running, _ = inspectField(cid, "State.Running")
132 119
 	if running != "true" {
133 120
 		c.Fatal("Container should be in running state after an invalid signal")
134 121
 	}