瀏覽代碼

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 10 年之前
父節點
當前提交
668e2369cc

+ 3 - 4
integration-cli/docker_cli_daemon_test.go

@@ -1276,13 +1276,12 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
 	}
 
 	args := append(dargs, "run", "-d", "--name", "container1", "busybox", "top")
-	_, err := runCommand(exec.Command(dockerBinary, args...))
-	c.Assert(err, check.IsNil)
+	dockerCmd(c, args...)
 
 	args = append(dargs, "run", "--rm", "--link", "container1:alias1", "busybox", "sh", "-c")
 	pingCmd := "ping -c 1 %s -W 1"
 	args = append(args, fmt.Sprintf(pingCmd, "alias1"))
-	_, err = runCommand(exec.Command(dockerBinary, args...))
+	_, _, err := dockerCmdWithError(c, args...)
 
 	if expectFailure {
 		c.Assert(err, check.NotNil)
@@ -1291,7 +1290,7 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
 	}
 
 	args = append(dargs, "rm", "-f", "container1")
-	runCommand(exec.Command(dockerBinary, args...))
+	dockerCmd(c, args...)
 }
 
 func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) {

+ 7 - 36
integration-cli/docker_cli_diff_test.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"os/exec"
 	"strings"
 
 	"github.com/go-check/check"
@@ -10,19 +9,10 @@ import (
 // ensure that an added file shows up in docker diff
 func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
 	containerCmd := `echo foo > /root/bar`
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("failed to start the container: %s, %v", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
 
 	cleanCID := strings.TrimSpace(out)
-
-	diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
-	out, _, err = runCommandWithOutput(diffCmd)
-	if err != nil {
-		c.Fatalf("failed to run diff: %s %v", out, err)
-	}
+	out, _ = dockerCmd(c, "diff", cleanCID)
 
 	found := false
 	for _, line := range strings.Split(out, "\n") {
@@ -45,20 +35,10 @@ func (s *DockerSuite) TestDiffEnsureDockerinitFilesAreIgnored(c *check.C) {
 	// we might not run into this problem from the first run, so start a few containers
 	for i := 0; i < containerCount; i++ {
 		containerCmd := `echo foo > /root/bar`
-		runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
-		out, _, err := runCommandWithOutput(runCmd)
-
-		if err != nil {
-			c.Fatal(out, err)
-		}
+		out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
 
 		cleanCID := strings.TrimSpace(out)
-
-		diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
-		out, _, err = runCommandWithOutput(diffCmd)
-		if err != nil {
-			c.Fatalf("failed to run diff: %s, %v", out, err)
-		}
+		out, _ = dockerCmd(c, "diff", cleanCID)
 
 		for _, filename := range dockerinitFiles {
 			if strings.Contains(out, filename) {
@@ -69,19 +49,10 @@ func (s *DockerSuite) TestDiffEnsureDockerinitFilesAreIgnored(c *check.C) {
 }
 
 func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "0")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "0")
 
 	cleanCID := strings.TrimSpace(out)
-
-	diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
-	out, _, err = runCommandWithOutput(diffCmd)
-	if err != nil {
-		c.Fatalf("failed to run diff: %s, %v", out, err)
-	}
+	out, _ = dockerCmd(c, "diff", cleanCID)
 
 	expected := map[string]bool{
 		"C /dev":         true,
@@ -111,7 +82,7 @@ func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) {
 
 // https://github.com/docker/docker/pull/14381#discussion_r33859347
 func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) {
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "diff", ""))
+	out, _, err := dockerCmdWithError(c, "diff", "")
 	c.Assert(err, check.NotNil)
 	c.Assert(strings.TrimSpace(out), check.Equals, "Container name cannot be empty")
 }

+ 44 - 207
integration-cli/docker_cli_events_test.go

@@ -34,11 +34,7 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
 	// --since=$start must contain only the 'untag' event
 	for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} {
 		since, until := f(start), f(end)
-		cmd := exec.Command(dockerBinary, "events", "--since="+since, "--until="+until)
-		out, _, err := runCommandWithOutput(cmd)
-		if err != nil {
-			c.Fatalf("docker events cmd failed: %v\nout=%s", err, out)
-		}
+		out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until)
 		events := strings.Split(strings.TrimSpace(out), "\n")
 		if len(events) != 2 {
 			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) {
 
 	out, _ := dockerCmd(c, "images", "-q")
 	image := strings.Split(out, "\n")[0]
-	if err := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg").Run(); err == nil {
+	if _, _, err := dockerCmdWithError(c, "run", "--name", "testeventdie", image, "blerg"); err == nil {
 		c.Fatalf("Container run with command blerg should have failed, but it did not")
 	}
 
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
-	out, _, _ = runCommandWithOutput(eventsCmd)
+	out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
 	events := strings.Split(out, "\n")
 	if len(events) <= 1 {
 		c.Fatalf("Missing expected event")
@@ -123,8 +118,7 @@ func (s *DockerSuite) TestEventsLimit(c *check.C) {
 		}
 	}
 
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
-	out, _, _ := runCommandWithOutput(eventsCmd)
+	out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
 	events := strings.Split(out, "\n")
 	nEvents := len(events) - 1
 	if nEvents != 64 {
@@ -134,11 +128,7 @@ func (s *DockerSuite) TestEventsLimit(c *check.C) {
 
 func (s *DockerSuite) TestEventsContainerEvents(c *check.C) {
 	dockerCmd(c, "run", "--rm", "busybox", "true")
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
-	out, exitCode, err := runCommandWithOutput(eventsCmd)
-	if exitCode != 0 || err != nil {
-		c.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
-	}
+	out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
 	events := strings.Split(out, "\n")
 	events = events[:len(events)-1]
 	if len(events) < 5 {
@@ -171,12 +161,8 @@ func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) {
 	dockerCmd(c, "run", "--rm", "busybox", "true")
 	timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano)
 	timeBeginning = strings.Replace(timeBeginning, "Z", ".000000000Z", -1)
-	eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since='%s'", timeBeginning),
+	out, _ := dockerCmd(c, "events", fmt.Sprintf("--since='%s'", timeBeginning),
 		fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
-	out, exitCode, err := runCommandWithOutput(eventsCmd)
-	if exitCode != 0 || err != nil {
-		c.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
-	}
 	events := strings.Split(out, "\n")
 	events = events[:len(events)-1]
 	if len(events) < 5 {
@@ -217,11 +203,7 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
 	if err := deleteImages(name); err != nil {
 		c.Fatal(err)
 	}
-	eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
-	out, exitCode, err := runCommandWithOutput(eventsCmd)
-	if exitCode != 0 || err != nil {
-		c.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
-	}
+	out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
 	events := strings.Split(out, "\n")
 
 	events = events[:len(events)-1]
@@ -244,11 +226,9 @@ func (s *DockerSuite) TestEventsImageTag(c *check.C) {
 	image := "testimageevents:tag"
 	dockerCmd(c, "tag", "busybox", image)
 
-	eventsCmd := exec.Command(dockerBinary, "events",
+	out, _ := dockerCmd(c, "events",
 		fmt.Sprintf("--since=%d", since),
 		fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
-	out, _, err := runCommandWithOutput(eventsCmd)
-	c.Assert(err, check.IsNil)
 
 	events := strings.Split(strings.TrimSpace(out), "\n")
 	if len(events) != 1 {
@@ -267,15 +247,11 @@ func (s *DockerSuite) TestEventsImagePull(c *check.C) {
 	since := daemonTime(c).Unix()
 	testRequires(c, Network)
 
-	pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
-	if out, _, err := runCommandWithOutput(pullCmd); err != nil {
-		c.Fatalf("pulling the hello-world image from has failed: %s, %v", out, err)
-	}
+	dockerCmd(c, "pull", "hello-world")
 
-	eventsCmd := exec.Command(dockerBinary, "events",
+	out, _ := dockerCmd(c, "events",
 		fmt.Sprintf("--since=%d", since),
 		fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
-	out, _, _ := runCommandWithOutput(eventsCmd)
 
 	events := strings.Split(strings.TrimSpace(out), "\n")
 	event := strings.TrimSpace(events[len(events)-1])
@@ -313,11 +289,7 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
 		}
 	}()
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to create a container", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
 	cleanedContainerID := strings.TrimSpace(out)
 
 	out, _, err = runCommandPipelineWithOutput(
@@ -352,24 +324,12 @@ func (s *DockerSuite) TestEventsFilters(c *check.C) {
 	}
 
 	since := daemonTime(c).Unix()
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
-	if err != nil {
-		c.Fatal(out, err)
-	}
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
-	if err != nil {
-		c.Fatal(out, err)
-	}
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die"))
-	if err != nil {
-		c.Fatalf("Failed to get events: %s", err)
-	}
+	dockerCmd(c, "run", "--rm", "busybox", "true")
+	dockerCmd(c, "run", "--rm", "busybox", "true")
+	out, _ := dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die")
 	parseEvents(out, "die")
 
-	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"))
-	if err != nil {
-		c.Fatalf("Failed to get events: %s", err)
-	}
+	out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", "event=die", "--filter", "event=start")
 	parseEvents(out, "((die)|(start))")
 
 	// make sure we at least got 2 start events
@@ -383,24 +343,14 @@ func (s *DockerSuite) TestEventsFilters(c *check.C) {
 func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
 	since := daemonTime(c).Unix()
 
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "-d", "busybox:latest", "true"))
-	if err != nil {
-		c.Fatal(out, err)
-	}
+	out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true")
 	container1 := strings.TrimSpace(out)
 
-	out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_2", "-d", "busybox", "true"))
-	if err != nil {
-		c.Fatal(out, err)
-	}
+	out, _ = dockerCmd(c, "run", "--name", "container_2", "-d", "busybox", "true")
 	container2 := strings.TrimSpace(out)
 
 	name := "busybox"
-	eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", fmt.Sprintf("image=%s", name))
-	out, _, err = runCommandWithOutput(eventsCmd)
-	if err != nil {
-		c.Fatalf("Failed to get events, error: %s(%s)", err, out)
-	}
+	out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", fmt.Sprintf("image=%s", name))
 	events := strings.Split(out, "\n")
 	events = events[:len(events)-1]
 	if len(events) == 0 {
@@ -427,10 +377,7 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
 	nameID := make(map[string]string)
 
 	for _, name := range []string{"container_1", "container_2"} {
-		out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", name, "busybox", "true"))
-		if err != nil {
-			c.Fatalf("Error: %v, Output: %s", err, out)
-		}
+		dockerCmd(c, "run", "--name", name, "busybox", "true")
 		id, err := inspectField(name, "Id")
 		if err != nil {
 			c.Fatal(err)
@@ -461,30 +408,19 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
 
 	for name, ID := range nameID {
 		// filter by names
-		eventsCmd := exec.Command(dockerBinary, "events", "--since", since, "--until", until, "--filter", "container="+name)
-		out, _, err := runCommandWithOutput(eventsCmd)
-		if err != nil {
-			c.Fatal(err)
-		}
-
+		out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name)
 		events := strings.Split(strings.TrimSuffix(out, "\n"), "\n")
 		if err := checkEvents(ID, events); err != nil {
 			c.Fatal(err)
 		}
 
 		// filter by ID's
-		eventsCmd = exec.Command(dockerBinary, "events", "--since", since, "--until", until, "--filter", "container="+ID)
-		out, _, err = runCommandWithOutput(eventsCmd)
-		if err != nil {
-			c.Fatal(err)
-		}
-
+		out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID)
 		events = strings.Split(strings.TrimSuffix(out, "\n"), "\n")
 		if err := checkEvents(ID, events); err != nil {
 			c.Fatal(err)
 		}
 	}
-
 }
 
 func (s *DockerSuite) TestEventsStreaming(c *check.C) {
@@ -529,11 +465,7 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
 		}
 	}()
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox:latest", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox:latest", "true")
 	cleanedContainerID := strings.TrimSpace(out)
 	id <- cleanedContainerID
 
@@ -558,11 +490,7 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
 		// ignore, done
 	}
 
-	rmCmd := exec.Command(dockerBinary, "rm", cleanedContainerID)
-	out, _, err = runCommandWithOutput(rmCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
+	dockerCmd(c, "rm", cleanedContainerID)
 
 	select {
 	case <-time.After(5 * time.Second):
@@ -575,32 +503,14 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
 func (s *DockerSuite) TestEventsCommit(c *check.C) {
 	since := daemonTime(c).Unix()
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("Couldn't run top: %s\n%q", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cID := strings.TrimSpace(out)
 	c.Assert(waitRun(cID), check.IsNil)
 
-	cmd := exec.Command(dockerBinary, "commit", "-m", "test", cID)
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't commit: %s\n%q", out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "stop", cID)
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
-	}
+	dockerCmd(c, "commit", "-m", "test", cID)
+	dockerCmd(c, "stop", cID)
 
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
 	if !strings.Contains(out, " commit\n") {
 		c.Fatalf("Missing 'commit' log event\n%s", out)
 	}
@@ -616,24 +526,10 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) {
 		c.Fatalf("Couldn't create image: %q", err)
 	}
 
-	runCmd := exec.Command(dockerBinary, "run", "--name=cptest", id, "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("Couldn't run top: %s\n%q", out, err)
-	}
-
-	cmd := exec.Command(dockerBinary, "cp", "cptest:/tmp/file", "-")
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Failed getting file:%q\n%q", out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
-	}
+	dockerCmd(c, "run", "--name=cptest", id, "true")
+	dockerCmd(c, "cp", "cptest:/tmp/file", "-")
 
+	out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
 	if !strings.Contains(out, " copy\n") {
 		c.Fatalf("Missing 'copy' log event\n%s", out)
 	}
@@ -642,11 +538,7 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) {
 func (s *DockerSuite) TestEventsResize(c *check.C) {
 	since := daemonTime(c).Unix()
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("Couldn't run top: %s\n%q", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cID := strings.TrimSpace(out)
 	c.Assert(waitRun(cID), check.IsNil)
 
@@ -655,18 +547,9 @@ func (s *DockerSuite) TestEventsResize(c *check.C) {
 	c.Assert(status, check.Equals, http.StatusOK)
 	c.Assert(err, check.IsNil)
 
-	cmd := exec.Command(dockerBinary, "stop", cID)
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
-	}
+	dockerCmd(c, "stop", cID)
 
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
 	if !strings.Contains(out, " resize\n") {
 		c.Fatalf("Missing 'resize' log event\n%s", out)
 	}
@@ -700,18 +583,9 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
 
 	c.Assert(stdin.Close(), check.IsNil)
 
-	cmd = exec.Command(dockerBinary, "stop", cID)
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
-	}
+	dockerCmd(c, "stop", cID)
 
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
 	if !strings.Contains(out, " attach\n") {
 		c.Fatalf("Missing 'attach' log event\n%s", out)
 	}
@@ -720,24 +594,10 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
 func (s *DockerSuite) TestEventsRename(c *check.C) {
 	since := daemonTime(c).Unix()
 
-	runCmd := exec.Command(dockerBinary, "run", "--name", "oldName", "busybox", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("Couldn't run true: %s\n%q", out, err)
-	}
-
-	renameCmd := exec.Command(dockerBinary, "rename", "oldName", "newName")
-	out, _, err = runCommandWithOutput(renameCmd)
-	if err != nil {
-		c.Fatalf("Couldn't rename: %s\n%q", out, err)
-	}
-
-	cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since)))
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
-	}
+	dockerCmd(c, "run", "--name", "oldName", "busybox", "true")
+	dockerCmd(c, "rename", "oldName", "newName")
 
+	out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since)))
 	if !strings.Contains(out, " rename\n") {
 		c.Fatalf("Missing 'rename' log event\n%s", out)
 	}
@@ -746,32 +606,14 @@ func (s *DockerSuite) TestEventsRename(c *check.C) {
 func (s *DockerSuite) TestEventsTop(c *check.C) {
 	since := daemonTime(c).Unix()
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("Couldn't run true: %s\n%q", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cID := strings.TrimSpace(out)
 	c.Assert(waitRun(cID), check.IsNil)
 
-	cmd := exec.Command(dockerBinary, "top", cID)
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't run docker top: %s\n%q", out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "stop", cID)
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't stop: %s\n%q", out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("Couldn't get events: %s\n%q", out, err)
-	}
+	dockerCmd(c, "top", cID)
+	dockerCmd(c, "stop", cID)
 
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
 	if !strings.Contains(out, " top\n") {
 		c.Fatalf("Missing 'top' log event\n%s", out)
 	}
@@ -790,9 +632,7 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
 	since := daemonTime(c).Unix()
 	repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL)
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	c.Assert(err, check.IsNil)
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cID := strings.TrimSpace(out)
 	c.Assert(waitRun(cID), check.IsNil)
 
@@ -800,10 +640,7 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
 	dockerCmd(c, "stop", cID)
 	dockerCmd(c, "push", repoName)
 
-	cmd := exec.Command(dockerBinary, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
-	out, _, err = runCommandWithOutput(cmd)
-	c.Assert(err, check.IsNil)
-
+	out, _ = dockerCmd(c, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
 	if !strings.Contains(out, repoName+": push\n") {
 		c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out)
 	}

+ 41 - 196
integration-cli/docker_cli_exec_test.go

@@ -19,32 +19,18 @@ import (
 )
 
 func (s *DockerSuite) TestExec(c *check.C) {
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
-
-	execCmd := exec.Command(dockerBinary, "exec", "testing", "cat", "/tmp/file")
-	out, _, err := runCommandWithOutput(execCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	out, _ := dockerCmd(c, "exec", "testing", "cat", "/tmp/file")
 	out = strings.Trim(out, "\r\n")
-
-	if expected := "test"; out != expected {
-		c.Errorf("container exec should've printed %q but printed %q", expected, out)
+	if out != "test" {
+		c.Errorf("container exec should've printed test but printed %q", out)
 	}
 
 }
 
 func (s *DockerSuite) TestExecInteractive(c *check.C) {
-
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
 
 	execCmd := exec.Command(dockerBinary, "exec", "-i", "testing", "sh")
 	stdin, err := execCmd.StdinPipe()
@@ -90,31 +76,15 @@ func (s *DockerSuite) TestExecInteractive(c *check.C) {
 }
 
 func (s *DockerSuite) TestExecAfterContainerRestart(c *check.C) {
-
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cleanedContainerID := strings.TrimSpace(out)
+	dockerCmd(c, "restart", cleanedContainerID)
 
-	runCmd = exec.Command(dockerBinary, "restart", cleanedContainerID)
-	if out, _, err = runCommandWithOutput(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
-
-	runCmd = exec.Command(dockerBinary, "exec", cleanedContainerID, "echo", "hello")
-	out, _, err = runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	out, _ = dockerCmd(c, "exec", cleanedContainerID, "echo", "hello")
 	outStr := strings.TrimSpace(out)
 	if outStr != "hello" {
 		c.Errorf("container should've printed hello, instead printed %q", outStr)
 	}
-
 }
 
 func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) {
@@ -149,65 +119,36 @@ func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) {
 
 // Regression test for #9155, #9044
 func (s *DockerSuite) TestExecEnv(c *check.C) {
-
-	runCmd := exec.Command(dockerBinary, "run",
-		"-e", "LALA=value1",
-		"-e", "LALA=value2",
+	dockerCmd(c, "run", "-e", "LALA=value1", "-e", "LALA=value2",
 		"-d", "--name", "testing", "busybox", "top")
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
-
-	execCmd := exec.Command(dockerBinary, "exec", "testing", "env")
-	out, _, err := runCommandWithOutput(execCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
 
+	out, _ := dockerCmd(c, "exec", "testing", "env")
 	if strings.Contains(out, "LALA=value1") ||
 		!strings.Contains(out, "LALA=value2") ||
 		!strings.Contains(out, "HOME=/root") {
 		c.Errorf("exec env(%q), expect %q, %q", out, "LALA=value2", "HOME=/root")
 	}
-
 }
 
 func (s *DockerSuite) TestExecExitStatus(c *check.C) {
-
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
-	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
+	dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
 
 	// Test normal (non-detached) case first
 	cmd := exec.Command(dockerBinary, "exec", "top", "sh", "-c", "exit 23")
 	ec, _ := runCommand(cmd)
-
 	if ec != 23 {
 		c.Fatalf("Should have had an ExitCode of 23, not: %d", ec)
 	}
-
 }
 
 func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
 	defer unpauseAllContainers()
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	out, _ := dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
 	ContainerID := strings.TrimSpace(out)
 
-	pausedCmd := exec.Command(dockerBinary, "pause", "testing")
-	out, _, _, err = runCommandWithStdoutStderr(pausedCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
-	execCmd := exec.Command(dockerBinary, "exec", "-i", "-t", ContainerID, "echo", "hello")
-	out, _, err = runCommandWithOutput(execCmd)
+	dockerCmd(c, "pause", "testing")
+	out, _, err := dockerCmdWithError(c, "exec", "-i", "-t", ContainerID, "echo", "hello")
 	if err == nil {
 		c.Fatal("container should fail to exec new command if it is paused")
 	}
@@ -216,18 +157,13 @@ func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
 	if !strings.Contains(out, expected) {
 		c.Fatal("container should not exec new command if it is paused")
 	}
-
 }
 
 // regression test for #9476
 func (s *DockerSuite) TestExecTtyCloseStdin(c *check.C) {
+	dockerCmd(c, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
 
-	cmd := exec.Command(dockerBinary, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox")
-	if out, _, err := runCommandWithOutput(cmd); err != nil {
-		c.Fatal(out, err)
-	}
-
-	cmd = exec.Command(dockerBinary, "exec", "-i", "exec_tty_stdin", "cat")
+	cmd := exec.Command(dockerBinary, "exec", "-i", "exec_tty_stdin", "cat")
 	stdinRw, err := cmd.StdinPipe()
 	if err != nil {
 		c.Fatal(err)
@@ -240,42 +176,22 @@ func (s *DockerSuite) TestExecTtyCloseStdin(c *check.C) {
 		c.Fatal(out, err)
 	}
 
-	cmd = exec.Command(dockerBinary, "top", "exec_tty_stdin")
-	out, _, err := runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	out, _ := dockerCmd(c, "top", "exec_tty_stdin")
 	outArr := strings.Split(out, "\n")
 	if len(outArr) > 3 || strings.Contains(out, "nsenter-exec") {
-		// This is the really bad part
-		if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rm", "-f", "exec_tty_stdin")); err != nil {
-			c.Fatal(out, err)
-		}
-
 		c.Fatalf("exec process left running\n\t %s", out)
 	}
-
 }
 
 func (s *DockerSuite) TestExecTtyWithoutStdin(c *check.C) {
-
-	cmd := exec.Command(dockerBinary, "run", "-d", "-ti", "busybox")
-	out, _, err := runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("failed to start container: %v (%v)", out, err)
-	}
-
+	out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox")
 	id := strings.TrimSpace(out)
 	if err := waitRun(id); err != nil {
 		c.Fatal(err)
 	}
 
 	defer func() {
-		cmd := exec.Command(dockerBinary, "kill", id)
-		if out, _, err := runCommandWithOutput(cmd); err != nil {
-			c.Fatalf("failed to kill container: %v (%v)", out, err)
-		}
+		dockerCmd(c, "kill", id)
 	}()
 
 	errChan := make(chan error)
@@ -304,15 +220,10 @@ func (s *DockerSuite) TestExecTtyWithoutStdin(c *check.C) {
 	case <-time.After(3 * time.Second):
 		c.Fatal("exec is running but should have failed")
 	}
-
 }
 
 func (s *DockerSuite) TestExecParseError(c *check.C) {
-
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
+	dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
 
 	// Test normal (non-detached) case first
 	cmd := exec.Command(dockerBinary, "exec", "top")
@@ -322,10 +233,7 @@ func (s *DockerSuite) TestExecParseError(c *check.C) {
 }
 
 func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
 
 	if err := exec.Command(dockerBinary, "exec", "testing", "top").Start(); err != nil {
 		c.Fatal(err)
@@ -351,20 +259,10 @@ func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
 }
 
 func (s *DockerSuite) TestExecCgroup(c *check.C) {
-	var cmd *exec.Cmd
-
-	cmd = exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "top")
-	_, err := runCommand(cmd)
-	if err != nil {
-		c.Fatal(err)
-	}
+	dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top")
 
-	cmd = exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/1/cgroup")
-	out, _, err := runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-	containerCgroups := sort.StringSlice(strings.Split(string(out), "\n"))
+	out, _ := dockerCmd(c, "exec", "testing", "cat", "/proc/1/cgroup")
+	containerCgroups := sort.StringSlice(strings.Split(out, "\n"))
 
 	var wg sync.WaitGroup
 	var mu sync.Mutex
@@ -374,13 +272,12 @@ func (s *DockerSuite) TestExecCgroup(c *check.C) {
 	for i := 0; i < 5; i++ {
 		wg.Add(1)
 		go func() {
-			cmd := exec.Command(dockerBinary, "exec", "testing", "cat", "/proc/self/cgroup")
-			out, _, err := runCommandWithOutput(cmd)
+			out, _, err := dockerCmdWithError(c, "exec", "testing", "cat", "/proc/self/cgroup")
 			if err != nil {
 				errChan <- err
 				return
 			}
-			cg := sort.StringSlice(strings.Split(string(out), "\n"))
+			cg := sort.StringSlice(strings.Split(out, "\n"))
 
 			mu.Lock()
 			execCgroups = append(execCgroups, cg)
@@ -409,18 +306,13 @@ func (s *DockerSuite) TestExecCgroup(c *check.C) {
 			c.Fatal("cgroups mismatched")
 		}
 	}
-
 }
 
 func (s *DockerSuite) TestInspectExecID(c *check.C) {
-
-	out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "top"))
-	if exitCode != 0 || err != nil {
-		c.Fatalf("failed to run container: %s, %v", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	id := strings.TrimSuffix(out, "\n")
 
-	out, err = inspectField(id, "ExecIDs")
+	out, err := inspectField(id, "ExecIDs")
 	if err != nil {
 		c.Fatalf("failed to inspect container: %s, %v", out, err)
 	}
@@ -496,29 +388,15 @@ func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) {
 		c.Fatal(out, "id should not be nil")
 	}
 
-	execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
-	out, _, err := runCommandWithOutput(execCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
 	dockerCmd(c, "rename", "container1", "container_new")
-
-	execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
-	out, _, err = runCommandWithOutput(execCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
 }
 
 func (s *DockerSuite) TestRunExecDir(c *check.C) {
 	testRequires(c, SameHostDaemon)
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatal(err, out)
-	}
+
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	id := strings.TrimSpace(out)
 	execDir := filepath.Join(execDriverPath, id)
 	stateFile := filepath.Join(execDir, "state.json")
@@ -537,11 +415,7 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
 		}
 	}
 
-	stopCmd := exec.Command(dockerBinary, "stop", id)
-	out, _, err = runCommandWithOutput(stopCmd)
-	if err != nil {
-		c.Fatal(err, out)
-	}
+	dockerCmd(c, "stop", id)
 	{
 		_, err := os.Stat(execDir)
 		if err == nil {
@@ -554,11 +428,7 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
 			c.Fatalf("Error should be about non-existing, got %s", err)
 		}
 	}
-	startCmd := exec.Command(dockerBinary, "start", id)
-	out, _, err = runCommandWithOutput(startCmd)
-	if err != nil {
-		c.Fatal(err, out)
-	}
+	dockerCmd(c, "start", id)
 	{
 		fi, err := os.Stat(execDir)
 		if err != nil {
@@ -572,11 +442,7 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
 			c.Fatal(err)
 		}
 	}
-	rmCmd := exec.Command(dockerBinary, "rm", "-f", id)
-	out, _, err = runCommandWithOutput(rmCmd)
-	if err != nil {
-		c.Fatal(err, out)
-	}
+	dockerCmd(c, "rm", "-f", id)
 	{
 		_, err := os.Stat(execDir)
 		if err == nil {
@@ -589,7 +455,6 @@ func (s *DockerSuite) TestRunExecDir(c *check.C) {
 			c.Fatalf("Error should be about non-existing, got %s", err)
 		}
 	}
-
 }
 
 func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
@@ -607,13 +472,8 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
 			c.Fatal("Content was not what was modified in the container", string(content))
 		}
 
-		out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "top"))
-		if err != nil {
-			c.Fatal(err)
-		}
-
+		out, _ := dockerCmd(c, "run", "-d", "--name", "c2", "busybox", "top")
 		contID := strings.TrimSpace(out)
-
 		netFilePath := containerStorageFile(contID, fn)
 
 		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) {
 		}
 		f.Close()
 
-		res, err := exec.Command(dockerBinary, "exec", contID, "cat", "/etc/"+fn).CombinedOutput()
-		if err != nil {
-			c.Fatalf("Output: %s, error: %s", res, err)
-		}
-		if string(res) != "success2\n" {
+		res, _ := dockerCmd(c, "exec", contID, "cat", "/etc/"+fn)
+		if res != "success2\n" {
 			c.Fatalf("Expected content of %s: %q, got: %q", fn, "success2\n", res)
 		}
 	}
 }
 
 func (s *DockerSuite) TestExecWithUser(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top")
-	if out, _, err := runCommandWithOutput(runCmd); err != nil {
-		c.Fatal(out, err)
-	}
+	dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
 
-	cmd := exec.Command(dockerBinary, "exec", "-u", "1", "parent", "id")
-	out, _, err := runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatal(err, out)
-	}
+	out, _ := dockerCmd(c, "exec", "-u", "1", "parent", "id")
 	if !strings.Contains(out, "uid=1(daemon) gid=1(daemon)") {
 		c.Fatalf("exec with user by id expected daemon user got %s", out)
 	}
 
-	cmd = exec.Command(dockerBinary, "exec", "-u", "root", "parent", "id")
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatal(err, out)
-	}
+	out, _ = dockerCmd(c, "exec", "-u", "root", "parent", "id")
 	if !strings.Contains(out, "uid=0(root) gid=0(root)") {
 		c.Fatalf("exec with user by root expected root user got %s", out)
 	}
-
 }
 
 func (s *DockerSuite) TestExecWithImageUser(c *check.C) {

+ 1 - 4
integration-cli/docker_cli_exec_unix_test.go

@@ -15,10 +15,7 @@ import (
 
 // regression test for #12546
 func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "busybox", "/bin/cat"))
-	if err != nil {
-		c.Fatal(err)
-	}
+	out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
 	contId := strings.TrimSpace(out)
 
 	cmd := exec.Command(dockerBinary, "exec", "-i", contId, "echo", "-n", "hello")

+ 4 - 10
integration-cli/docker_cli_experimental_test.go

@@ -3,27 +3,21 @@
 package main
 
 import (
-	"os/exec"
 	"strings"
 
 	"github.com/go-check/check"
 )
 
 func (s *DockerSuite) TestExperimentalVersion(c *check.C) {
-	versionCmd := exec.Command(dockerBinary, "version")
-	out, _, err := runCommandWithOutput(versionCmd)
-	if err != nil {
-		c.Fatalf("failed to execute docker version: %s, %v", out, err)
-	}
-
+	out, _ := dockerCmd(c, "version")
 	for _, line := range strings.Split(out, "\n") {
 		if strings.HasPrefix(line, "Experimental (client):") || strings.HasPrefix(line, "Experimental (server):") {
 			c.Assert(line, check.Matches, "*true")
 		}
 	}
 
-	versionCmd = exec.Command(dockerBinary, "-v")
-	if out, _, err = runCommandWithOutput(versionCmd); err != nil || !strings.Contains(out, ", experimental") {
-		c.Fatalf("docker version did not contain experimental: %s, %v", out, err)
+	out, _ = dockerCmd(c, "-v")
+	if !strings.Contains(out, ", experimental") {
+		c.Fatalf("docker version did not contain experimental: %s", out)
 	}
 }

+ 6 - 22
integration-cli/docker_cli_export_import_test.go

@@ -12,20 +12,13 @@ import (
 func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
 	containerID := "testexportcontainerandimportimage"
 
-	runCmd := exec.Command(dockerBinary, "run", "--name", containerID, "busybox", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to create a container", out, err)
-	}
+	dockerCmd(c, "run", "--name", containerID, "busybox", "true")
 
-	exportCmd := exec.Command(dockerBinary, "export", containerID)
-	if out, _, err = runCommandWithOutput(exportCmd); err != nil {
-		c.Fatalf("failed to export container: %s, %v", out, err)
-	}
+	out, _ := dockerCmd(c, "export", containerID)
 
 	importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
 	importCmd.Stdin = strings.NewReader(out)
-	out, _, err = runCommandWithOutput(importCmd)
+	out, _, err := runCommandWithOutput(importCmd)
 	if err != nil {
 		c.Fatalf("failed to import image: %s, %v", out, err)
 	}
@@ -40,20 +33,11 @@ func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
 func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
 	containerID := "testexportcontainerwithoutputandimportimage"
 
-	runCmd := exec.Command(dockerBinary, "run", "--name", containerID, "busybox", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to create a container", out, err)
-	}
-
+	dockerCmd(c, "run", "--name", containerID, "busybox", "true")
+	dockerCmd(c, "export", "--output=testexp.tar", containerID)
 	defer os.Remove("testexp.tar")
 
-	exportCmd := exec.Command(dockerBinary, "export", "--output=testexp.tar", containerID)
-	if out, _, err = runCommandWithOutput(exportCmd); err != nil {
-		c.Fatalf("failed to export container: %s, %v", out, err)
-	}
-
-	out, _, err = runCommandWithOutput(exec.Command("cat", "testexp.tar"))
+	out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar"))
 	if err != nil {
 		c.Fatal(out, err)
 	}

+ 11 - 39
integration-cli/docker_cli_history_test.go

@@ -2,7 +2,6 @@ package main
 
 import (
 	"fmt"
-	"os/exec"
 	"regexp"
 	"strconv"
 	"strings"
@@ -47,11 +46,7 @@ RUN echo "Z"`,
 		c.Fatal(err)
 	}
 
-	out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "history", "testbuildhistory"))
-	if err != nil || exitCode != 0 {
-		c.Fatalf("failed to get image history: %s, %v", out, err)
-	}
-
+	out, _ := dockerCmd(c, "history", "testbuildhistory")
 	actualValues := strings.Split(out, "\n")[1:27]
 	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"}
 
@@ -67,18 +62,13 @@ RUN echo "Z"`,
 }
 
 func (s *DockerSuite) TestHistoryExistentImage(c *check.C) {
-	historyCmd := exec.Command(dockerBinary, "history", "busybox")
-	_, exitCode, err := runCommandWithOutput(historyCmd)
-	if err != nil || exitCode != 0 {
-		c.Fatal("failed to get image history")
-	}
+	dockerCmd(c, "history", "busybox")
 }
 
 func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) {
-	historyCmd := exec.Command(dockerBinary, "history", "testHistoryNonExistentImage")
-	_, exitCode, err := runCommandWithOutput(historyCmd)
-	if err == nil || exitCode == 0 {
-		c.Fatal("history on a non-existent image didn't result in a non-zero exit status")
+	_, _, err := dockerCmdWithError(c, "history", "testHistoryNonExistentImage")
+	if err == nil {
+		c.Fatal("history on a non-existent image should fail.")
 	}
 }
 
@@ -86,44 +76,26 @@ func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
 	name := "testhistoryimagewithcomment"
 
 	// make a image through docker commit <container id> [ -m messages ]
-	//runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
-	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("failed to run container: %s, %v", out, err)
-	}
 
-	waitCmd := exec.Command(dockerBinary, "wait", name)
-	if out, _, err := runCommandWithOutput(waitCmd); err != nil {
-		c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
-	}
+	dockerCmd(c, "run", "--name", name, "busybox", "true")
+	dockerCmd(c, "wait", name)
 
 	comment := "This_is_a_comment"
-
-	commitCmd := exec.Command(dockerBinary, "commit", "-m="+comment, name, name)
-	if out, _, err := runCommandWithOutput(commitCmd); err != nil {
-		c.Fatalf("failed to commit container to image: %s, %v", out, err)
-	}
+	dockerCmd(c, "commit", "-m="+comment, name, name)
 
 	// test docker history <image id> to check comment messages
-	historyCmd := exec.Command(dockerBinary, "history", name)
-	out, exitCode, err := runCommandWithOutput(historyCmd)
-	if err != nil || exitCode != 0 {
-		c.Fatalf("failed to get image history: %s, %v", out, err)
-	}
 
+	out, _ := dockerCmd(c, "history", name)
 	outputTabs := strings.Fields(strings.Split(out, "\n")[1])
-	//outputTabs := regexp.MustCompile("  +").Split(outputLine, -1)
 	actualValue := outputTabs[len(outputTabs)-1]
 
 	if !strings.Contains(actualValue, comment) {
 		c.Fatalf("Expected comments %q, but found %q", comment, actualValue)
 	}
-
 }
 
 func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
-	out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "history", "--human=false", "busybox"))
+	out, _ := dockerCmd(c, "history", "--human=false", "busybox")
 	lines := strings.Split(out, "\n")
 	sizeColumnRegex, _ := regexp.Compile("SIZE +")
 	indices := sizeColumnRegex.FindStringIndex(lines[0])
@@ -141,7 +113,7 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
 }
 
 func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) {
-	out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "history", "--human=true", "busybox"))
+	out, _ := dockerCmd(c, "history", "--human=true", "busybox")
 	lines := strings.Split(out, "\n")
 	sizeColumnRegex, _ := regexp.Compile("SIZE +")
 	humanSizeRegex, _ := regexp.Compile("^\\d+.*B$") // Matches human sizes like 10 MB, 3.2 KB, etc

+ 12 - 60
integration-cli/docker_cli_images_test.go

@@ -2,7 +2,6 @@ package main
 
 import (
 	"fmt"
-	"os/exec"
 	"reflect"
 	"sort"
 	"strings"
@@ -13,16 +12,10 @@ import (
 )
 
 func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) {
-	imagesCmd := exec.Command(dockerBinary, "images")
-	out, _, err := runCommandWithOutput(imagesCmd)
-	if err != nil {
-		c.Fatalf("listing images failed with errors: %s, %v", out, err)
-	}
-
+	out, _ := dockerCmd(c, "images")
 	if !strings.Contains(out, "busybox") {
 		c.Fatal("images should've listed busybox")
 	}
-
 }
 
 func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
@@ -47,10 +40,7 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
 		c.Fatal(err)
 	}
 
-	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "images", "-q", "--no-trunc"))
-	if err != nil {
-		c.Fatalf("listing images failed with errors: %s, %v", out, err)
-	}
+	out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
 	imgs := strings.Split(out, "\n")
 	if imgs[0] != id3 {
 		c.Fatalf("First image must be %s, got %s", id3, imgs[0])
@@ -61,16 +51,13 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
 	if imgs[2] != id1 {
 		c.Fatalf("Third image must be %s, got %s", id1, imgs[2])
 	}
-
 }
 
 func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) {
-	imagesCmd := exec.Command(dockerBinary, "images", "-f", "FOO=123")
-	out, _, err := runCommandWithOutput(imagesCmd)
-	if !strings.Contains(out, "Invalid filter") {
-		c.Fatalf("error should occur when listing images with invalid filter name FOO, %s, %v", out, err)
+	out, _, err := dockerCmdWithError(c, "images", "-f", "FOO=123")
+	if err == nil || !strings.Contains(out, "Invalid filter") {
+		c.Fatalf("error should occur when listing images with invalid filter name FOO, %s", out)
 	}
-
 }
 
 func (s *DockerSuite) TestImagesFilterLabel(c *check.C) {
@@ -98,28 +85,17 @@ func (s *DockerSuite) TestImagesFilterLabel(c *check.C) {
 		c.Fatal(err)
 	}
 
-	cmd := exec.Command(dockerBinary, "images", "--no-trunc", "-q", "-f", "label=match")
-	out, _, err := runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
+	out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
 	out = strings.TrimSpace(out)
-
 	if (!strings.Contains(out, image1ID) && !strings.Contains(out, image2ID)) || strings.Contains(out, image3ID) {
 		c.Fatalf("Expected ids %s,%s got %s", image1ID, image2ID, out)
 	}
 
-	cmd = exec.Command(dockerBinary, "images", "--no-trunc", "-q", "-f", "label=match=me too")
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
+	out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too")
 	out = strings.TrimSpace(out)
-
 	if out != image2ID {
 		c.Fatalf("Expected %s got %s", image2ID, out)
 	}
-
 }
 
 func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
@@ -140,11 +116,7 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
 
 	imageListings := make([][]string, 5, 5)
 	for idx, filter := range filters {
-		cmd := exec.Command(dockerBinary, "images", "-q", "-f", filter)
-		out, _, err := runCommandWithOutput(cmd)
-		if err != nil {
-			c.Fatal(err)
-		}
+		out, _ := dockerCmd(c, "images", "-q", "-f", filter)
 		listing := strings.Split(out, "\n")
 		sort.Strings(listing)
 		imageListings[idx] = listing
@@ -162,42 +134,22 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
 			c.Fatalf("All output must be the same")
 		}
 	}
-
 }
 
 func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
-
 	// create container 1
-	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
-	out, _, err := runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("error running busybox: %s, %v", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
 	containerId1 := strings.TrimSpace(out)
 
 	// tag as foobox
-	cmd = exec.Command(dockerBinary, "commit", containerId1, "foobox")
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("error tagging foobox: %s", err)
-	}
+	out, _ = dockerCmd(c, "commit", containerId1, "foobox")
 	imageId := stringid.TruncateID(strings.TrimSpace(out))
 
 	// overwrite the tag, making the previous image dangling
-	cmd = exec.Command(dockerBinary, "tag", "-f", "busybox", "foobox")
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("error tagging foobox: %s", err)
-	}
-
-	cmd = exec.Command(dockerBinary, "images", "-q", "-f", "dangling=true")
-	out, _, err = runCommandWithOutput(cmd)
-	if err != nil {
-		c.Fatalf("listing images failed with errors: %s, %v", out, err)
-	}
+	dockerCmd(c, "tag", "-f", "busybox", "foobox")
 
+	out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
 	if e, a := 1, strings.Count(out, imageId); e != a {
 		c.Fatalf("expected 1 dangling image, got %d: %s", a, out)
 	}
-
 }

+ 10 - 38
integration-cli/docker_cli_import_test.go

@@ -11,14 +11,10 @@ import (
 )
 
 func (s *DockerSuite) TestImportDisplay(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to create a container", out, err)
-	}
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
 	cleanedContainerID := strings.TrimSpace(out)
 
-	out, _, err = runCommandPipelineWithOutput(
+	out, _, err := runCommandPipelineWithOutput(
 		exec.Command(dockerBinary, "export", cleanedContainerID),
 		exec.Command(dockerBinary, "import", "-"),
 	)
@@ -31,21 +27,14 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
 	}
 	image := strings.TrimSpace(out)
 
-	runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
-	out, _, err = runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to create a container", out, err)
-	}
-
+	out, _ = dockerCmd(c, "run", "--rm", image, "true")
 	if out != "" {
 		c.Fatalf("command output should've been nothing, was %q", out)
 	}
-
 }
 
 func (s *DockerSuite) TestImportBadURL(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "import", "http://nourl/bad")
-	out, _, err := runCommandWithOutput(runCmd)
+	out, _, err := dockerCmdWithError(c, "import", "http://nourl/bad")
 	if err == nil {
 		c.Fatal("import was supposed to fail but didn't")
 	}
@@ -55,11 +44,7 @@ func (s *DockerSuite) TestImportBadURL(c *check.C) {
 }
 
 func (s *DockerSuite) TestImportFile(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "--name", "test-import", "busybox", "true")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to create a container", out, err)
-	}
+	dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
 
 	temporaryFile, err := ioutil.TempFile("", "exportImportTest")
 	if err != nil {
@@ -67,42 +52,29 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
 	}
 	defer os.Remove(temporaryFile.Name())
 
-	runCmd = exec.Command(dockerBinary, "export", "test-import")
+	runCmd := exec.Command(dockerBinary, "export", "test-import")
 	runCmd.Stdout = bufio.NewWriter(temporaryFile)
 
 	_, err = runCommand(runCmd)
 	if err != nil {
-		c.Fatal("failed to export a container", out, err)
-	}
-
-	runCmd = exec.Command(dockerBinary, "import", temporaryFile.Name())
-	out, _, err = runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to import a container", out, err)
+		c.Fatal("failed to export a container", err)
 	}
 
+	out, _ := dockerCmd(c, "import", temporaryFile.Name())
 	if n := strings.Count(out, "\n"); n != 1 {
 		c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
 	}
 	image := strings.TrimSpace(out)
 
-	runCmd = exec.Command(dockerBinary, "run", "--rm", image, "true")
-	out, _, err = runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal("failed to create a container", out, err)
-	}
-
+	out, _ = dockerCmd(c, "run", "--rm", image, "true")
 	if out != "" {
 		c.Fatalf("command output should've been nothing, was %q", out)
 	}
-
 }
 
 func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "import", "example.com/myImage.tar")
-	_, exitCode, err := runCommandWithOutput(runCmd)
+	_, exitCode, err := dockerCmdWithError(c, "import", "example.com/myImage.tar")
 	if exitCode == 0 || err == nil {
 		c.Fatalf("import non-existing file must failed")
 	}
-
 }

+ 1 - 6
integration-cli/docker_cli_info_test.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"os/exec"
 	"strings"
 
 	"github.com/docker/docker/utils"
@@ -10,11 +9,7 @@ import (
 
 // ensure docker info succeeds
 func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
-	versionCmd := exec.Command(dockerBinary, "info")
-	out, exitCode, err := runCommandWithOutput(versionCmd)
-	if err != nil || exitCode != 0 {
-		c.Fatalf("failed to execute docker info: %s, %v", out, err)
-	}
+	out, _ := dockerCmd(c, "info")
 
 	// always shown fields
 	stringsToCheck := []string{

+ 13 - 60
integration-cli/docker_cli_inspect_test.go

@@ -18,7 +18,6 @@ func (s *DockerSuite) TestInspectImage(c *check.C) {
 	if id != imageTestID {
 		c.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestID, imageTest, id)
 	}
-
 }
 
 func (s *DockerSuite) TestInspectInt64(c *check.C) {
@@ -27,7 +26,6 @@ func (s *DockerSuite) TestInspectInt64(c *check.C) {
 	if err != nil {
 		c.Fatalf("failed to run container: %v, output: %q", err, out)
 	}
-
 	out = strings.TrimSpace(out)
 
 	inspectOut, err := inspectField(out, "HostConfig.Memory")
@@ -43,18 +41,8 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) {
 	//Both the container and image are named busybox. docker inspect will fetch the container JSON.
 	//If the container JSON is not available, it will go for the image JSON.
 
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "true")
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
-	if err != nil {
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
-	}
-
-	inspectCmd := exec.Command(dockerBinary, "inspect", "busybox")
-
-	_, exitCode, err := runCommandWithOutput(inspectCmd)
-	if exitCode != 0 || err != nil {
-		c.Fatalf("failed to inspect container: %s, %v", out, err)
-	}
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
+	dockerCmd(c, "inspect", "busybox")
 }
 
 func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
@@ -62,16 +50,10 @@ func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
 	//Both the container and image are named busybox. docker inspect will fetch container
 	//JSON State.Running field. If the field is true, it's a container.
 
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "top")
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
-	if err != nil {
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
-	}
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
 
 	formatStr := fmt.Sprintf("--format='{{.State.Running}}'")
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=container", formatStr, "busybox")
-
-	out, exitCode, err := runCommandWithOutput(inspectCmd)
+	out, exitCode, err := dockerCmdWithError(c, "inspect", "--type=container", formatStr, "busybox")
 	if exitCode != 0 || err != nil {
 		c.Fatalf("failed to inspect container: %s, %v", out, err)
 	}
@@ -87,15 +69,9 @@ func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *check.C) {
 	//JSON. Since there is no container named busybox and --type=container, docker inspect will
 	//not try to get the image JSON. It will throw an error.
 
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
-	if err != nil {
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
-	}
-
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=container", "busybox")
+	dockerCmd(c, "run", "-d", "busybox", "true")
 
-	_, exitCode, err := runCommandWithOutput(inspectCmd)
+	_, exitCode, err := dockerCmdWithError(c, "inspect", "--type=container", "busybox")
 	if exitCode == 0 || err == nil {
 		c.Fatalf("docker inspect should have failed, as there is no container named busybox")
 	}
@@ -107,15 +83,9 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
 	//JSON as --type=image. if there is no image with name busybox, docker inspect
 	//will throw an error.
 
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "true")
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
-	if err != nil {
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
-	}
-
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=image", "busybox")
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
 
-	out, exitCode, err := runCommandWithOutput(inspectCmd)
+	out, exitCode, err := dockerCmdWithError(c, "inspect", "--type=image", "busybox")
 	if exitCode != 0 || err != nil {
 		c.Fatalf("failed to inspect image: %s, %v", out, err)
 	}
@@ -123,7 +93,6 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
 	if strings.Contains(out, "State") {
 		c.Fatal("not an image JSON")
 	}
-
 }
 
 func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
@@ -131,15 +100,9 @@ func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
 	//Both the container and image are named busybox. docker inspect will fail
 	//as --type=foobar is not a valid value for the flag.
 
-	runCmd := exec.Command(dockerBinary, "run", "--name=busybox", "-d", "busybox", "true")
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
-	if err != nil {
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
-	}
-
-	inspectCmd := exec.Command(dockerBinary, "inspect", "--type=foobar", "busybox")
+	dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
 
-	out, exitCode, err := runCommandWithOutput(inspectCmd)
+	out, exitCode, err := dockerCmdWithError(c, "inspect", "--type=foobar", "busybox")
 	if exitCode != 0 || err != nil {
 		if !strings.Contains(out, "not a valid value for --type") {
 			c.Fatalf("failed to inspect image: %s, %v", out, err)
@@ -159,8 +122,7 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
 
 	//now see if the size turns out to be the same
 	formatStr := fmt.Sprintf("--format='{{eq .Size %d}}'", size)
-	imagesCmd := exec.Command(dockerBinary, "inspect", formatStr, imageTest)
-	out, exitCode, err := runCommandWithOutput(imagesCmd)
+	out, exitCode, err := dockerCmdWithError(c, "inspect", formatStr, imageTest)
 	if exitCode != 0 || err != nil {
 		c.Fatalf("failed to inspect image: %s, %v", out, err)
 	}
@@ -189,11 +151,7 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
 
 	//now get the exit code to verify
 	formatStr := fmt.Sprintf("--format='{{eq .State.ExitCode %d}}'", exitCode)
-	runCmd = exec.Command(dockerBinary, "inspect", formatStr, id)
-	out, _, err = runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatalf("failed to inspect container: %s, %v", out, err)
-	}
+	out, _ = dockerCmd(c, "inspect", formatStr, id)
 	if result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")); err != nil || !result {
 		c.Fatalf("Expected exitcode: %d for container: %s", exitCode, id)
 	}
@@ -230,12 +188,7 @@ func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
 }
 
 func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
-	if err != nil {
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
-	}
-
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
 	out = strings.TrimSpace(out)
 
 	name, err := inspectField(out, "GraphDriver.Name")

+ 18 - 64
integration-cli/docker_cli_kill_test.go

@@ -1,75 +1,42 @@
 package main
 
 import (
-	"os/exec"
 	"strings"
 
 	"github.com/go-check/check"
 )
 
 func (s *DockerSuite) TestKillContainer(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cleanedContainerID := strings.TrimSpace(out)
 	c.Assert(waitRun(cleanedContainerID), check.IsNil)
 
-	killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
-	if out, _, err = runCommandWithOutput(killCmd); err != nil {
-		c.Fatalf("failed to kill container: %s, %v", out, err)
-	}
-
-	listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q")
-	out, _, err = runCommandWithOutput(listRunningContainersCmd)
-	if err != nil {
-		c.Fatalf("failed to list running containers: %s, %v", out, err)
-	}
+	dockerCmd(c, "kill", cleanedContainerID)
 
+	out, _ = dockerCmd(c, "ps", "-q")
 	if strings.Contains(out, cleanedContainerID) {
 		c.Fatal("killed container is still running")
 	}
 }
 
 func (s *DockerSuite) TestKillofStoppedContainer(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	c.Assert(err, check.IsNil)
-
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cleanedContainerID := strings.TrimSpace(out)
 
-	stopCmd := exec.Command(dockerBinary, "stop", cleanedContainerID)
-	out, _, err = runCommandWithOutput(stopCmd)
-	c.Assert(err, check.IsNil)
+	dockerCmd(c, "stop", cleanedContainerID)
 
-	killCmd := exec.Command(dockerBinary, "kill", "-s", "30", cleanedContainerID)
-	_, _, err = runCommandWithOutput(killCmd)
+	_, _, err := dockerCmdWithError(c, "kill", "-s", "30", cleanedContainerID)
 	c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID))
 }
 
 func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	if err != nil {
-		c.Fatal(out, err)
-	}
-
+	out, _ := dockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top")
 	cleanedContainerID := strings.TrimSpace(out)
 	c.Assert(waitRun(cleanedContainerID), check.IsNil)
 
-	killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
-	if out, _, err = runCommandWithOutput(killCmd); err != nil {
-		c.Fatalf("failed to kill container: %s, %v", out, err)
-	}
-
-	listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q")
-	out, _, err = runCommandWithOutput(listRunningContainersCmd)
-	if err != nil {
-		c.Fatalf("failed to list running containers: %s, %v", out, err)
-	}
+	dockerCmd(c, "kill", cleanedContainerID)
 
+	out, _ = dockerCmd(c, "ps", "-q")
 	if strings.Contains(out, cleanedContainerID) {
 		c.Fatal("killed container is still running")
 	}
@@ -77,58 +44,45 @@ func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
 
 // regression test about correct signal parsing see #13665
 func (s *DockerSuite) TestKillWithSignal(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	c.Assert(err, check.IsNil)
-
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cid := strings.TrimSpace(out)
 	c.Assert(waitRun(cid), check.IsNil)
 
-	killCmd := exec.Command(dockerBinary, "kill", "-s", "SIGWINCH", cid)
-	_, err = runCommand(killCmd)
-	c.Assert(err, check.IsNil)
+	dockerCmd(c, "kill", "-s", "SIGWINCH", cid)
 
-	running, err := inspectField(cid, "State.Running")
+	running, _ := inspectField(cid, "State.Running")
 	if running != "true" {
 		c.Fatal("Container should be in running state after SIGWINCH")
 	}
 }
 
 func (s *DockerSuite) TestKillWithInvalidSignal(c *check.C) {
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err := runCommandWithOutput(runCmd)
-	c.Assert(err, check.IsNil)
-
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
 	cid := strings.TrimSpace(out)
 	c.Assert(waitRun(cid), check.IsNil)
 
-	killCmd := exec.Command(dockerBinary, "kill", "-s", "0", cid)
-	out, _, err = runCommandWithOutput(killCmd)
+	out, _, err := dockerCmdWithError(c, "kill", "-s", "0", cid)
 	c.Assert(err, check.NotNil)
 	if !strings.ContainsAny(out, "Invalid signal: 0") {
 		c.Fatal("Kill with an invalid signal didn't error out correctly")
 	}
 
-	running, err := inspectField(cid, "State.Running")
+	running, _ := inspectField(cid, "State.Running")
 	if running != "true" {
 		c.Fatal("Container should be in running state after an invalid signal")
 	}
 
-	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
-	out, _, err = runCommandWithOutput(runCmd)
-	c.Assert(err, check.IsNil)
-
+	out, _ = dockerCmd(c, "run", "-d", "busybox", "top")
 	cid = strings.TrimSpace(out)
 	c.Assert(waitRun(cid), check.IsNil)
 
-	killCmd = exec.Command(dockerBinary, "kill", "-s", "SIG42", cid)
-	out, _, err = runCommandWithOutput(killCmd)
+	out, _, err = dockerCmdWithError(c, "kill", "-s", "SIG42", cid)
 	c.Assert(err, check.NotNil)
 	if !strings.ContainsAny(out, "Invalid signal: SIG42") {
 		c.Fatal("Kill with an invalid signal error out correctly")
 	}
 
-	running, err = inspectField(cid, "State.Running")
+	running, _ = inspectField(cid, "State.Running")
 	if running != "true" {
 		c.Fatal("Container should be in running state after an invalid signal")
 	}