Browse code

Clean integration-cli/utils.go from most of its content

Most of the code is now on pkg/integration.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/12/14 05:21:51
Showing 23 changed files
... ...
@@ -19,6 +19,7 @@ import (
19 19
 
20 20
 	"github.com/docker/docker/builder/dockerfile/command"
21 21
 	"github.com/docker/docker/pkg/archive"
22
+	"github.com/docker/docker/pkg/integration"
22 23
 	"github.com/docker/docker/pkg/integration/checker"
23 24
 	icmd "github.com/docker/docker/pkg/integration/cmd"
24 25
 	"github.com/docker/docker/pkg/stringutils"
... ...
@@ -2085,7 +2086,7 @@ func (s *DockerSuite) TestBuildContextCleanup(c *check.C) {
2085 2085
 	if err != nil {
2086 2086
 		c.Fatalf("failed to list contents of tmp dir: %s", err)
2087 2087
 	}
2088
-	if err = compareDirectoryEntries(entries, entriesFinal); err != nil {
2088
+	if err = integration.CompareDirectoryEntries(entries, entriesFinal); err != nil {
2089 2089
 		c.Fatalf("context should have been deleted, but wasn't")
2090 2090
 	}
2091 2091
 
... ...
@@ -2110,7 +2111,7 @@ func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) {
2110 2110
 	if err != nil {
2111 2111
 		c.Fatalf("failed to list contents of tmp dir: %s", err)
2112 2112
 	}
2113
-	if err = compareDirectoryEntries(entries, entriesFinal); err != nil {
2113
+	if err = integration.CompareDirectoryEntries(entries, entriesFinal); err != nil {
2114 2114
 		c.Fatalf("context should have been deleted, but wasn't")
2115 2115
 	}
2116 2116
 
... ...
@@ -5341,7 +5342,7 @@ func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) {
5341 5341
 	if err != nil {
5342 5342
 		c.Fatalf("failed to read '/proc/self/cgroup - %v", err)
5343 5343
 	}
5344
-	selfCgroupPaths := parseCgroupPaths(string(data))
5344
+	selfCgroupPaths := integration.ParseCgroupPaths(string(data))
5345 5345
 	_, found := selfCgroupPaths["memory"]
5346 5346
 	if !found {
5347 5347
 		c.Fatalf("unable to find self memory cgroup path. CgroupsPath: %v", selfCgroupPaths)
... ...
@@ -6242,11 +6243,10 @@ func (s *DockerSuite) TestBuildMultipleTags(c *check.C) {
6242 6242
 	FROM busybox
6243 6243
 	MAINTAINER test-15780
6244 6244
 	`
6245
-	cmd := exec.Command(dockerBinary, "build", "-t", "tag1", "-t", "tag2:v2",
6246
-		"-t", "tag1:latest", "-t", "tag1", "--no-cache", "-")
6247
-	cmd.Stdin = strings.NewReader(dockerfile)
6248
-	_, err := runCommand(cmd)
6249
-	c.Assert(err, check.IsNil)
6245
+	icmd.RunCmd(icmd.Cmd{
6246
+		Command: []string{dockerBinary, "build", "-t", "tag1", "-t", "tag2:v2", "-t", "tag1:latest", "-t", "tag1", "--no-cache", "-"},
6247
+		Stdin:   strings.NewReader(dockerfile),
6248
+	}).Assert(c, icmd.Success)
6250 6249
 
6251 6250
 	id1, err := getIDByName("tag1")
6252 6251
 	c.Assert(err, check.IsNil)
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"path/filepath"
11 11
 	"strings"
12 12
 
13
+	"github.com/docker/docker/pkg/integration"
13 14
 	"github.com/docker/docker/pkg/integration/checker"
14 15
 	icmd "github.com/docker/docker/pkg/integration/cmd"
15 16
 	"github.com/go-check/check"
... ...
@@ -545,7 +546,7 @@ func (s *DockerSuite) TestCpToStdout(c *check.C) {
545 545
 	// failed to set up container
546 546
 	c.Assert(strings.TrimSpace(out), checker.Equals, "0")
547 547
 
548
-	out, _, err := runCommandPipelineWithOutput(
548
+	out, _, err := integration.RunCommandPipelineWithOutput(
549 549
 		exec.Command(dockerBinary, "cp", containerID+":/test", "-"),
550 550
 		exec.Command("tar", "-vtf", "-"))
551 551
 
... ...
@@ -12,6 +12,7 @@ import (
12 12
 
13 13
 	"io/ioutil"
14 14
 
15
+	"github.com/docker/docker/pkg/integration"
15 16
 	"github.com/docker/docker/pkg/integration/checker"
16 17
 	"github.com/docker/docker/pkg/stringid"
17 18
 	"github.com/docker/go-connections/nat"
... ...
@@ -355,7 +356,7 @@ func (s *DockerTrustSuite) TestCreateWhenCertExpired(c *check.C) {
355 355
 	// Certificates have 10 years of expiration
356 356
 	elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11)
357 357
 
358
-	runAtDifferentDate(elevenYearsFromNow, func() {
358
+	integration.RunAtDifferentDate(elevenYearsFromNow, func() {
359 359
 		// Try create
360 360
 		createCmd := exec.Command(dockerBinary, "create", repoName)
361 361
 		s.trustedCmd(createCmd)
... ...
@@ -364,7 +365,7 @@ func (s *DockerTrustSuite) TestCreateWhenCertExpired(c *check.C) {
364 364
 		c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf("Missing expected output on trusted create in the distant future:\n%s", out))
365 365
 	})
366 366
 
367
-	runAtDifferentDate(elevenYearsFromNow, func() {
367
+	integration.RunAtDifferentDate(elevenYearsFromNow, func() {
368 368
 		// Try create
369 369
 		createCmd := exec.Command(dockerBinary, "create", "--disable-content-trust", repoName)
370 370
 		s.trustedCmd(createCmd)
... ...
@@ -21,6 +21,7 @@ import (
21 21
 	"time"
22 22
 
23 23
 	"github.com/docker/docker/integration-cli/daemon"
24
+	"github.com/docker/docker/pkg/integration"
24 25
 	"github.com/docker/docker/pkg/integration/checker"
25 26
 	icmd "github.com/docker/docker/pkg/integration/cmd"
26 27
 	"github.com/docker/docker/pkg/mount"
... ...
@@ -235,11 +236,7 @@ func (s *DockerDaemonSuite) TestDaemonStartBridgeWithoutIPAssociation(c *check.C
235 235
 	s.d.Stop(c)
236 236
 
237 237
 	// now we will remove the ip from docker0 and then try starting the daemon
238
-	ipCmd := exec.Command("ip", "addr", "flush", "dev", "docker0")
239
-	stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
240
-	if err != nil {
241
-		c.Fatalf("failed to remove docker0 IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
242
-	}
238
+	icmd.RunCommand("ip", "addr", "flush", "dev", "docker0").Assert(c, icmd.Success)
243 239
 
244 240
 	if err := s.d.StartWithError(); err != nil {
245 241
 		warning := "**WARNING: Docker bridge network in bad state--delete docker0 bridge interface to fix"
... ...
@@ -668,24 +665,16 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
668 668
 	defer d.Restart(c)
669 669
 
670 670
 	ifconfigSearchString := ip.String()
671
-	ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge)
672
-	out, _, _, err := runCommandWithStdoutStderr(ifconfigCmd)
673
-	c.Assert(err, check.IsNil)
674
-
675
-	c.Assert(strings.Contains(out, ifconfigSearchString), check.Equals, true,
676
-		check.Commentf("ifconfig output should have contained %q, but was %q",
677
-			ifconfigSearchString, out))
671
+	icmd.RunCommand("ifconfig", defaultNetworkBridge).Assert(c, icmd.Expected{
672
+		Out: ifconfigSearchString,
673
+	})
678 674
 
679 675
 	ipTablesSearchString := bridgeIPNet.String()
680
-	ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
681
-	out, _, err = runCommandWithOutput(ipTablesCmd)
682
-	c.Assert(err, check.IsNil)
683
-
684
-	c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true,
685
-		check.Commentf("iptables output should have contained %q, but was %q",
686
-			ipTablesSearchString, out))
676
+	icmd.RunCommand("iptables", "-t", "nat", "-nvL").Assert(c, icmd.Expected{
677
+		Out: ipTablesSearchString,
678
+	})
687 679
 
688
-	out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top")
680
+	_, err := d.Cmd("run", "-d", "--name", "test", "busybox", "top")
689 681
 	c.Assert(err, check.IsNil)
690 682
 
691 683
 	containerIP, err := d.FindContainerIP("test")
... ...
@@ -706,24 +695,15 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithBridgeIPChange(c *check.C) {
706 706
 	bridgeIP := "192.169.100.1/24"
707 707
 	_, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
708 708
 
709
-	ipCmd := exec.Command("ifconfig", "docker0", bridgeIP)
710
-	stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
711
-	if err != nil {
712
-		c.Fatalf("failed to change docker0's IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
713
-	}
709
+	icmd.RunCommand("ifconfig", "docker0", bridgeIP).Assert(c, icmd.Success)
714 710
 
715 711
 	s.d.Start(c, "--bip", bridgeIP)
716 712
 
717 713
 	//check if the iptables contains new bridgeIP MASQUERADE rule
718 714
 	ipTablesSearchString := bridgeIPNet.String()
719
-	ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
720
-	out, _, err := runCommandWithOutput(ipTablesCmd)
721
-	if err != nil {
722
-		c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
723
-	}
724
-	if !strings.Contains(out, ipTablesSearchString) {
725
-		c.Fatalf("iptables output should have contained new MASQUERADE rule with IP %q, but was %q", ipTablesSearchString, out)
726
-	}
715
+	icmd.RunCommand("iptables", "-t", "nat", "-nvL").Assert(c, icmd.Expected{
716
+		Out: ipTablesSearchString,
717
+	})
727 718
 }
728 719
 
729 720
 func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) {
... ...
@@ -1908,7 +1888,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) {
1908 1908
 
1909 1909
 	out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup")
1910 1910
 	c.Assert(err, checker.IsNil)
1911
-	cgroupPaths := parseCgroupPaths(string(out))
1911
+	cgroupPaths := integration.ParseCgroupPaths(string(out))
1912 1912
 	c.Assert(len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out)))
1913 1913
 	out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name)
1914 1914
 	c.Assert(err, checker.IsNil)
... ...
@@ -14,6 +14,7 @@ import (
14 14
 
15 15
 	eventtypes "github.com/docker/docker/api/types/events"
16 16
 	eventstestutils "github.com/docker/docker/daemon/events/testutils"
17
+	"github.com/docker/docker/pkg/integration"
17 18
 	"github.com/docker/docker/pkg/integration/checker"
18 19
 	icmd "github.com/docker/docker/pkg/integration/cmd"
19 20
 	"github.com/go-check/check"
... ...
@@ -221,7 +222,7 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
221 221
 	cleanedContainerID := strings.TrimSpace(out)
222 222
 
223 223
 	since := daemonUnixTime(c)
224
-	out, _, err := runCommandPipelineWithOutput(
224
+	out, _, err := integration.RunCommandPipelineWithOutput(
225 225
 		exec.Command(dockerBinary, "export", cleanedContainerID),
226 226
 		exec.Command(dockerBinary, "import", "-"),
227 227
 	)
... ...
@@ -206,6 +206,7 @@ func (s *DockerSuite) TestExecTTYWithoutStdin(c *check.C) {
206 206
 	}
207 207
 }
208 208
 
209
+// FIXME(vdemeester) this should be a unit tests on cli/command/container package
209 210
 func (s *DockerSuite) TestExecParseError(c *check.C) {
210 211
 	// TODO Windows CI: Requires some extra work. Consider copying the
211 212
 	// runSleepingContainer helper to have an exec version.
... ...
@@ -213,10 +214,11 @@ func (s *DockerSuite) TestExecParseError(c *check.C) {
213 213
 	dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
214 214
 
215 215
 	// Test normal (non-detached) case first
216
-	cmd := exec.Command(dockerBinary, "exec", "top")
217
-	_, stderr, _, err := runCommandWithStdoutStderr(cmd)
218
-	c.Assert(err, checker.NotNil)
219
-	c.Assert(stderr, checker.Contains, "See 'docker exec --help'")
216
+	icmd.RunCommand(dockerBinary, "exec", "top").Assert(c, icmd.Expected{
217
+		ExitCode: 1,
218
+		Error:    "exit status 1",
219
+		Err:      "See 'docker exec --help'",
220
+	})
220 221
 }
221 222
 
222 223
 func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
... ...
@@ -147,56 +147,56 @@ func (s *DockerSuite) TestHelpExitCodesHelpOutput(c *check.C) {
147 147
 	// various good and bad cases are what we expect
148 148
 
149 149
 	// docker : stdout=all, stderr=empty, rc=0
150
-	out, _, err := dockerCmdWithError()
151
-	c.Assert(err, checker.IsNil, check.Commentf(out))
150
+	out, _ := dockerCmd(c)
152 151
 	// Be really pick
153 152
 	c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker'\n"))
154 153
 
155 154
 	// docker help: stdout=all, stderr=empty, rc=0
156
-	out, _, err = dockerCmdWithError("help")
157
-	c.Assert(err, checker.IsNil, check.Commentf(out))
155
+	out, _ = dockerCmd(c, "help")
158 156
 	// Be really pick
159 157
 	c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker help'\n"))
160 158
 
161 159
 	// docker --help: stdout=all, stderr=empty, rc=0
162
-	out, _, err = dockerCmdWithError("--help")
163
-	c.Assert(err, checker.IsNil, check.Commentf(out))
160
+	out, _ = dockerCmd(c, "--help")
164 161
 	// Be really pick
165 162
 	c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker --help'\n"))
166 163
 
167 164
 	// docker inspect busybox: stdout=all, stderr=empty, rc=0
168 165
 	// Just making sure stderr is empty on valid cmd
169
-	out, _, err = dockerCmdWithError("inspect", "busybox")
170
-	c.Assert(err, checker.IsNil, check.Commentf(out))
166
+	out, _ = dockerCmd(c, "inspect", "busybox")
171 167
 	// Be really pick
172 168
 	c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker inspect busyBox'\n"))
173 169
 
174 170
 	// docker rm: stdout=empty, stderr=all, rc!=0
175 171
 	// testing the min arg error msg
176
-	cmd := exec.Command(dockerBinary, "rm")
177
-	stdout, stderr, _, err := runCommandWithStdoutStderr(cmd)
178
-	c.Assert(err, checker.NotNil)
179
-	c.Assert(stdout, checker.Equals, "")
180
-	// Should not contain full help text but should contain info about
181
-	// # of args and Usage line
182
-	c.Assert(stderr, checker.Contains, "requires at least 1 argument", check.Commentf("Missing # of args text from 'docker rm'\n"))
172
+	icmd.RunCommand(dockerBinary, "rm").Assert(c, icmd.Expected{
173
+		ExitCode: 1,
174
+		Error:    "exit status 1",
175
+		Out:      "",
176
+		// Should not contain full help text but should contain info about
177
+		// # of args and Usage line
178
+		Err: "requires at least 1 argument",
179
+	})
183 180
 
184 181
 	// docker rm NoSuchContainer: stdout=empty, stderr=all, rc=0
185 182
 	// testing to make sure no blank line on error
186
-	cmd = exec.Command(dockerBinary, "rm", "NoSuchContainer")
187
-	stdout, stderr, _, err = runCommandWithStdoutStderr(cmd)
188
-	c.Assert(err, checker.NotNil)
189
-	c.Assert(len(stderr), checker.Not(checker.Equals), 0)
190
-	c.Assert(stdout, checker.Equals, "")
183
+	result := icmd.RunCommand(dockerBinary, "rm", "NoSuchContainer")
184
+	result.Assert(c, icmd.Expected{
185
+		ExitCode: 1,
186
+		Error:    "exit status 1",
187
+		Out:      "",
188
+	})
191 189
 	// Be really picky
192
-	c.Assert(stderr, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker rm'\n"))
190
+	c.Assert(len(result.Stderr()), checker.Not(checker.Equals), 0)
191
+	c.Assert(result.Stderr(), checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker rm'\n"))
193 192
 
194 193
 	// docker BadCmd: stdout=empty, stderr=all, rc=0
195
-	cmd = exec.Command(dockerBinary, "BadCmd")
196
-	stdout, stderr, _, err = runCommandWithStdoutStderr(cmd)
197
-	c.Assert(err, checker.NotNil)
198
-	c.Assert(stdout, checker.Equals, "")
199
-	c.Assert(stderr, checker.Equals, "docker: 'BadCmd' is not a docker command.\nSee 'docker --help'\n", check.Commentf("Unexcepted output for 'docker badCmd'\n"))
194
+	icmd.RunCommand(dockerBinary, "BadCmd").Assert(c, icmd.Expected{
195
+		ExitCode: 1,
196
+		Error:    "exit status 1",
197
+		Out:      "",
198
+		Err:      "docker: 'BadCmd' is not a docker command.\nSee 'docker --help'\n",
199
+	})
200 200
 }
201 201
 
202 202
 func testCommand(cmd string, newEnvs []string, scanForHome bool, home string) error {
... ...
@@ -204,9 +204,13 @@ func testCommand(cmd string, newEnvs []string, scanForHome bool, home string) er
204 204
 	args := strings.Split(cmd+" --help", " ")
205 205
 
206 206
 	// Check the full usage text
207
-	helpCmd := exec.Command(dockerBinary, args...)
208
-	helpCmd.Env = newEnvs
209
-	out, stderr, _, err := runCommandWithStdoutStderr(helpCmd)
207
+	result := icmd.RunCmd(icmd.Cmd{
208
+		Command: append([]string{dockerBinary}, args...),
209
+		Env:     newEnvs,
210
+	})
211
+	err := result.Error
212
+	out := result.Stdout()
213
+	stderr := result.Stderr()
210 214
 	if len(stderr) != 0 {
211 215
 		return fmt.Errorf("Error on %q help. non-empty stderr:%q\n", cmd, stderr)
212 216
 	}
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"regexp"
10 10
 	"strings"
11 11
 
12
+	"github.com/docker/docker/pkg/integration"
12 13
 	"github.com/docker/docker/pkg/integration/checker"
13 14
 	icmd "github.com/docker/docker/pkg/integration/cmd"
14 15
 	"github.com/go-check/check"
... ...
@@ -19,7 +20,7 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
19 19
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
20 20
 	cleanedContainerID := strings.TrimSpace(out)
21 21
 
22
-	out, _, err := runCommandPipelineWithOutput(
22
+	out, _, err := integration.RunCommandPipelineWithOutput(
23 23
 		exec.Command(dockerBinary, "export", cleanedContainerID),
24 24
 		exec.Command(dockerBinary, "import", "-"),
25 25
 	)
... ...
@@ -51,11 +52,10 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
51 51
 	c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
52 52
 	defer os.Remove(temporaryFile.Name())
53 53
 
54
-	runCmd := exec.Command(dockerBinary, "export", "test-import")
55
-	runCmd.Stdout = bufio.NewWriter(temporaryFile)
56
-
57
-	_, err = runCommand(runCmd)
58
-	c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
54
+	icmd.RunCmd(icmd.Cmd{
55
+		Command: []string{dockerBinary, "export", "test-import"},
56
+		Stdout:  bufio.NewWriter(temporaryFile),
57
+	}).Assert(c, icmd.Success)
59 58
 
60 59
 	out, _ := dockerCmd(c, "import", temporaryFile.Name())
61 60
 	c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
... ...
@@ -73,14 +73,12 @@ func (s *DockerSuite) TestImportGzipped(c *check.C) {
73 73
 	c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
74 74
 	defer os.Remove(temporaryFile.Name())
75 75
 
76
-	runCmd := exec.Command(dockerBinary, "export", "test-import")
77 76
 	w := gzip.NewWriter(temporaryFile)
78
-	runCmd.Stdout = w
79
-
80
-	_, err = runCommand(runCmd)
81
-	c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
82
-	err = w.Close()
83
-	c.Assert(err, checker.IsNil, check.Commentf("failed to close gzip writer"))
77
+	icmd.RunCmd(icmd.Cmd{
78
+		Command: []string{dockerBinary, "export", "test-import"},
79
+		Stdout:  w,
80
+	}).Assert(c, icmd.Success)
81
+	c.Assert(w.Close(), checker.IsNil, check.Commentf("failed to close gzip writer"))
84 82
 	temporaryFile.Close()
85 83
 	out, _ := dockerCmd(c, "import", temporaryFile.Name())
86 84
 	c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
... ...
@@ -98,11 +96,10 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
98 98
 	c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
99 99
 	defer os.Remove(temporaryFile.Name())
100 100
 
101
-	runCmd := exec.Command(dockerBinary, "export", "test-import")
102
-	runCmd.Stdout = bufio.NewWriter(temporaryFile)
103
-
104
-	_, err = runCommand(runCmd)
105
-	c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
101
+	icmd.RunCmd(icmd.Cmd{
102
+		Command: []string{dockerBinary, "export", "test-import"},
103
+		Stdout:  bufio.NewWriter(temporaryFile),
104
+	}).Assert(c, icmd.Success)
106 105
 
107 106
 	message := "Testing commit message"
108 107
 	out, _ := dockerCmd(c, "import", "-m", message, temporaryFile.Name())
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6 6
 	"os"
7
-	"os/exec"
8 7
 	"strconv"
9 8
 	"strings"
10 9
 	"time"
... ...
@@ -12,6 +11,7 @@ import (
12 12
 	"github.com/docker/docker/api/types"
13 13
 	"github.com/docker/docker/api/types/container"
14 14
 	"github.com/docker/docker/pkg/integration/checker"
15
+	icmd "github.com/docker/docker/pkg/integration/cmd"
15 16
 	"github.com/go-check/check"
16 17
 )
17 18
 
... ...
@@ -142,11 +142,12 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
142 142
 }
143 143
 
144 144
 func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
145
-	runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat")
146
-	runCmd.Stdin = strings.NewReader("blahblah")
147
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
148
-	c.Assert(err, checker.IsNil, check.Commentf("failed to run container: %v, output: %q", err, out))
149
-
145
+	result := icmd.RunCmd(icmd.Cmd{
146
+		Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
147
+		Stdin:   strings.NewReader("blahblah"),
148
+	})
149
+	result.Assert(c, icmd.Success)
150
+	out := result.Stdout()
150 151
 	id := strings.TrimSpace(out)
151 152
 
152 153
 	out = inspectField(c, id, "State.ExitCode")
... ...
@@ -157,9 +158,9 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
157 157
 	//now get the exit code to verify
158 158
 	formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
159 159
 	out, _ = dockerCmd(c, "inspect", formatStr, id)
160
-	result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
160
+	inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
161 161
 	c.Assert(err, checker.IsNil)
162
-	c.Assert(result, checker.Equals, true)
162
+	c.Assert(inspectResult, checker.Equals, true)
163 163
 }
164 164
 
165 165
 func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"regexp"
7 7
 	"strings"
8 8
 
9
+	"github.com/docker/docker/pkg/integration"
9 10
 	"github.com/docker/docker/pkg/integration/checker"
10 11
 	"github.com/docker/docker/runconfig"
11 12
 	"github.com/go-check/check"
... ...
@@ -101,7 +102,7 @@ func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
101 101
 	err := json.Unmarshal([]byte(links), &result)
102 102
 	c.Assert(err, checker.IsNil)
103 103
 
104
-	output := convertSliceOfStringsToMap(result)
104
+	output := integration.ConvertSliceOfStringsToMap(result)
105 105
 
106 106
 	c.Assert(output, checker.DeepEquals, expected)
107 107
 }
... ...
@@ -120,7 +121,7 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
120 120
 	err := json.Unmarshal([]byte(links), &result)
121 121
 	c.Assert(err, checker.IsNil)
122 122
 
123
-	output := convertSliceOfStringsToMap(result)
123
+	output := integration.ConvertSliceOfStringsToMap(result)
124 124
 
125 125
 	c.Assert(output, checker.DeepEquals, expected)
126 126
 }
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"strings"
9 9
 	"time"
10 10
 
11
+	"github.com/docker/docker/pkg/integration"
11 12
 	"github.com/docker/docker/pkg/integration/checker"
12 13
 	"github.com/docker/docker/pkg/jsonlog"
13 14
 	"github.com/go-check/check"
... ...
@@ -253,11 +254,11 @@ func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) {
253 253
 	c.Assert(logCmd.Start(), checker.IsNil)
254 254
 
255 255
 	// First read slowly
256
-	bytes1, err := consumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead)
256
+	bytes1, err := integration.ConsumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead)
257 257
 	c.Assert(err, checker.IsNil)
258 258
 
259 259
 	// After the container has finished we can continue reading fast
260
-	bytes2, err := consumeWithSpeed(stdout, 32*1024, 0, nil)
260
+	bytes2, err := integration.ConsumeWithSpeed(stdout, 32*1024, 0, nil)
261 261
 	c.Assert(err, checker.IsNil)
262 262
 
263 263
 	actual := bytes1 + bytes2
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"strings"
8 8
 	"time"
9 9
 
10
+	"github.com/docker/docker/pkg/integration"
10 11
 	"github.com/docker/docker/pkg/integration/checker"
11 12
 	"github.com/go-check/check"
12 13
 )
... ...
@@ -69,7 +70,7 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
69 69
 	// Certificates have 10 years of expiration
70 70
 	elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11)
71 71
 
72
-	runAtDifferentDate(elevenYearsFromNow, func() {
72
+	integration.RunAtDifferentDate(elevenYearsFromNow, func() {
73 73
 		// Try pull
74 74
 		pullCmd := exec.Command(dockerBinary, "pull", repoName)
75 75
 		s.trustedCmd(pullCmd)
... ...
@@ -79,7 +80,7 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
79 79
 		c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf(out))
80 80
 	})
81 81
 
82
-	runAtDifferentDate(elevenYearsFromNow, func() {
82
+	integration.RunAtDifferentDate(elevenYearsFromNow, func() {
83 83
 		// Try pull
84 84
 		pullCmd := exec.Command(dockerBinary, "pull", "--disable-content-trust", repoName)
85 85
 		s.trustedCmd(pullCmd)
... ...
@@ -166,7 +167,7 @@ func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
166 166
 	// Snapshots last for three years. This should be expired
167 167
 	fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
168 168
 
169
-	runAtDifferentDate(fourYearsLater, func() {
169
+	integration.RunAtDifferentDate(fourYearsLater, func() {
170 170
 		// Try pull
171 171
 		pullCmd := exec.Command(dockerBinary, "pull", repoName)
172 172
 		s.trustedCmd(pullCmd)
... ...
@@ -15,6 +15,7 @@ import (
15 15
 
16 16
 	"github.com/docker/distribution/reference"
17 17
 	cliconfig "github.com/docker/docker/cli/config"
18
+	"github.com/docker/docker/pkg/integration"
18 19
 	"github.com/docker/docker/pkg/integration/checker"
19 20
 	"github.com/go-check/check"
20 21
 )
... ...
@@ -437,7 +438,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
437 437
 	// Snapshots last for three years. This should be expired
438 438
 	fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
439 439
 
440
-	runAtDifferentDate(fourYearsLater, func() {
440
+	integration.RunAtDifferentDate(fourYearsLater, func() {
441 441
 		// Push with wrong passphrases
442 442
 		pushCmd = exec.Command(dockerBinary, "push", repoName)
443 443
 		s.trustedCmd(pushCmd)
... ...
@@ -464,7 +465,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
464 464
 	threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
465 465
 
466 466
 	// Should succeed because the server transparently re-signs one
467
-	runAtDifferentDate(threeWeeksLater, func() {
467
+	integration.RunAtDifferentDate(threeWeeksLater, func() {
468 468
 		pushCmd := exec.Command(dockerBinary, "push", repoName)
469 469
 		s.trustedCmd(pushCmd)
470 470
 		out, _, err := runCommandWithOutput(pushCmd)
... ...
@@ -21,6 +21,7 @@ import (
21 21
 	"sync"
22 22
 	"time"
23 23
 
24
+	"github.com/docker/docker/pkg/integration"
24 25
 	"github.com/docker/docker/pkg/integration/checker"
25 26
 	icmd "github.com/docker/docker/pkg/integration/cmd"
26 27
 	"github.com/docker/docker/pkg/mount"
... ...
@@ -92,12 +93,12 @@ func (s *DockerSuite) TestRunExitCodeOne(c *check.C) {
92 92
 func (s *DockerSuite) TestRunStdinPipe(c *check.C) {
93 93
 	// TODO Windows: This needs some work to make compatible.
94 94
 	testRequires(c, DaemonIsLinux)
95
-	runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat")
96
-	runCmd.Stdin = strings.NewReader("blahblah")
97
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
98
-	if err != nil {
99
-		c.Fatalf("failed to run container: %v, output: %q", err, out)
100
-	}
95
+	result := icmd.RunCmd(icmd.Cmd{
96
+		Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
97
+		Stdin:   strings.NewReader("blahblah"),
98
+	})
99
+	result.Assert(c, icmd.Success)
100
+	out := result.Stdout()
101 101
 
102 102
 	out = strings.TrimSpace(out)
103 103
 	dockerCmd(c, "wait", out)
... ...
@@ -497,7 +498,7 @@ func (s *DockerSuite) TestRunVolumesFromInReadWriteMode(c *check.C) {
497 497
 func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) {
498 498
 	testRequires(c, SameHostDaemon)
499 499
 	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
500
-	hostpath := randomTmpDirPath("test", daemonPlatform)
500
+	hostpath := integration.RandomTmpDirPath("test", daemonPlatform)
501 501
 	if err := os.MkdirAll(hostpath, 0755); err != nil {
502 502
 		c.Fatalf("Failed to create %s: %q", hostpath, err)
503 503
 	}
... ...
@@ -520,8 +521,8 @@ func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) {
520 520
 
521 521
 // Test for GH#10618
522 522
 func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) {
523
-	path1 := randomTmpDirPath("test1", daemonPlatform)
524
-	path2 := randomTmpDirPath("test2", daemonPlatform)
523
+	path1 := integration.RandomTmpDirPath("test1", daemonPlatform)
524
+	path2 := integration.RandomTmpDirPath("test2", daemonPlatform)
525 525
 
526 526
 	someplace := ":/someplace"
527 527
 	if daemonPlatform == "windows" {
... ...
@@ -1453,10 +1454,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
1453 1453
 		c.Fatal(err)
1454 1454
 	}
1455 1455
 	if mounted {
1456
-		cmd := exec.Command("umount", "/etc/resolv.conf")
1457
-		if _, err = runCommand(cmd); err != nil {
1458
-			c.Fatal(err)
1459
-		}
1456
+		icmd.RunCommand("umount", "/etc/resolv.conf").Assert(c, icmd.Success)
1460 1457
 	}
1461 1458
 
1462 1459
 	//cleanup
... ...
@@ -1656,13 +1654,11 @@ func (s *DockerSuite) TestRunAttachStdOutAndErrTTYMode(c *check.C) {
1656 1656
 // Test for #10388 - this will run the same test as TestRunAttachStdOutAndErrTTYMode
1657 1657
 // but using --attach instead of -a to make sure we read the flag correctly
1658 1658
 func (s *DockerSuite) TestRunAttachWithDetach(c *check.C) {
1659
-	cmd := exec.Command(dockerBinary, "run", "-d", "--attach", "stdout", "busybox", "true")
1660
-	_, stderr, _, err := runCommandWithStdoutStderr(cmd)
1661
-	if err == nil {
1662
-		c.Fatal("Container should have exited with error code different than 0")
1663
-	} else if !strings.Contains(stderr, "Conflicting options: -a and -d") {
1664
-		c.Fatal("Should have been returned an error with conflicting options -a and -d")
1665
-	}
1659
+	icmd.RunCommand(dockerBinary, "run", "-d", "--attach", "stdout", "busybox", "true").Assert(c, icmd.Expected{
1660
+		ExitCode: 1,
1661
+		Error:    "exit status 1",
1662
+		Err:      "Conflicting options: -a and -d",
1663
+	})
1666 1664
 }
1667 1665
 
1668 1666
 func (s *DockerSuite) TestRunState(c *check.C) {
... ...
@@ -2279,7 +2275,7 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) {
2279 2279
 		c.Fatalf("Data was copied on volumes-from but shouldn't be:\n%q", out)
2280 2280
 	}
2281 2281
 
2282
-	tmpDir := randomTmpDirPath("docker_test_bind_mount_copy_data", daemonPlatform)
2282
+	tmpDir := integration.RandomTmpDirPath("docker_test_bind_mount_copy_data", daemonPlatform)
2283 2283
 	if out, _, err := dockerCmdWithError("run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") {
2284 2284
 		c.Fatalf("Data was copied on bind-mount but shouldn't be:\n%q", out)
2285 2285
 	}
... ...
@@ -2348,7 +2344,7 @@ func (s *DockerSuite) TestRunSlowStdoutConsumer(c *check.C) {
2348 2348
 	if err := cont.Start(); err != nil {
2349 2349
 		c.Fatal(err)
2350 2350
 	}
2351
-	n, err := consumeWithSpeed(stdout, 10000, 5*time.Millisecond, nil)
2351
+	n, err := integration.ConsumeWithSpeed(stdout, 10000, 5*time.Millisecond, nil)
2352 2352
 	if err != nil {
2353 2353
 		c.Fatal(err)
2354 2354
 	}
... ...
@@ -3330,7 +3326,7 @@ func (s *DockerTrustSuite) TestRunWhenCertExpired(c *check.C) {
3330 3330
 	// Certificates have 10 years of expiration
3331 3331
 	elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11)
3332 3332
 
3333
-	runAtDifferentDate(elevenYearsFromNow, func() {
3333
+	integration.RunAtDifferentDate(elevenYearsFromNow, func() {
3334 3334
 		// Try run
3335 3335
 		runCmd := exec.Command(dockerBinary, "run", repoName)
3336 3336
 		s.trustedCmd(runCmd)
... ...
@@ -3344,7 +3340,7 @@ func (s *DockerTrustSuite) TestRunWhenCertExpired(c *check.C) {
3344 3344
 		}
3345 3345
 	})
3346 3346
 
3347
-	runAtDifferentDate(elevenYearsFromNow, func() {
3347
+	integration.RunAtDifferentDate(elevenYearsFromNow, func() {
3348 3348
 		// Try run
3349 3349
 		runCmd := exec.Command(dockerBinary, "run", "--disable-content-trust", repoName)
3350 3350
 		s.trustedCmd(runCmd)
... ...
@@ -3536,7 +3532,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) {
3536 3536
 	if err != nil {
3537 3537
 		c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
3538 3538
 	}
3539
-	cgroupPaths := parseCgroupPaths(string(out))
3539
+	cgroupPaths := integration.ParseCgroupPaths(string(out))
3540 3540
 	if len(cgroupPaths) == 0 {
3541 3541
 		c.Fatalf("unexpected output - %q", string(out))
3542 3542
 	}
... ...
@@ -3565,7 +3561,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) {
3565 3565
 	if err != nil {
3566 3566
 		c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
3567 3567
 	}
3568
-	cgroupPaths := parseCgroupPaths(string(out))
3568
+	cgroupPaths := integration.ParseCgroupPaths(string(out))
3569 3569
 	if len(cgroupPaths) == 0 {
3570 3570
 		c.Fatalf("unexpected output - %q", string(out))
3571 3571
 	}
... ...
@@ -3604,7 +3600,7 @@ func (s *DockerSuite) TestRunInvalidCgroupParent(c *check.C) {
3604 3604
 		c.Fatalf("SECURITY: --cgroup-parent with ../../ relative paths cause files to be created in the host (this is bad) !!")
3605 3605
 	}
3606 3606
 
3607
-	cgroupPaths := parseCgroupPaths(string(out))
3607
+	cgroupPaths := integration.ParseCgroupPaths(string(out))
3608 3608
 	if len(cgroupPaths) == 0 {
3609 3609
 		c.Fatalf("unexpected output - %q", string(out))
3610 3610
 	}
... ...
@@ -3643,7 +3639,7 @@ func (s *DockerSuite) TestRunAbsoluteInvalidCgroupParent(c *check.C) {
3643 3643
 		c.Fatalf("SECURITY: --cgroup-parent with /../../ garbage paths cause files to be created in the host (this is bad) !!")
3644 3644
 	}
3645 3645
 
3646
-	cgroupPaths := parseCgroupPaths(string(out))
3646
+	cgroupPaths := integration.ParseCgroupPaths(string(out))
3647 3647
 	if len(cgroupPaths) == 0 {
3648 3648
 		c.Fatalf("unexpected output - %q", string(out))
3649 3649
 	}
... ...
@@ -4151,15 +4147,8 @@ func (s *DockerSuite) TestRunVolumesMountedAsShared(c *check.C) {
4151 4151
 
4152 4152
 	// Convert this directory into a shared mount point so that we do
4153 4153
 	// not rely on propagation properties of parent mount.
4154
-	cmd := exec.Command("mount", "--bind", tmpDir, tmpDir)
4155
-	if _, err = runCommand(cmd); err != nil {
4156
-		c.Fatal(err)
4157
-	}
4158
-
4159
-	cmd = exec.Command("mount", "--make-private", "--make-shared", tmpDir)
4160
-	if _, err = runCommand(cmd); err != nil {
4161
-		c.Fatal(err)
4162
-	}
4154
+	icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
4155
+	icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
4163 4156
 
4164 4157
 	dockerCmd(c, "run", "--privileged", "-v", fmt.Sprintf("%s:/volume-dest:shared", tmpDir), "busybox", "mount", "--bind", "/volume-dest/mnt1", "/volume-dest/mnt1")
4165 4158
 
... ...
@@ -4201,25 +4190,15 @@ func (s *DockerSuite) TestRunVolumesMountedAsSlave(c *check.C) {
4201 4201
 
4202 4202
 	// Convert this directory into a shared mount point so that we do
4203 4203
 	// not rely on propagation properties of parent mount.
4204
-	cmd := exec.Command("mount", "--bind", tmpDir, tmpDir)
4205
-	if _, err = runCommand(cmd); err != nil {
4206
-		c.Fatal(err)
4207
-	}
4208
-
4209
-	cmd = exec.Command("mount", "--make-private", "--make-shared", tmpDir)
4210
-	if _, err = runCommand(cmd); err != nil {
4211
-		c.Fatal(err)
4212
-	}
4204
+	icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
4205
+	icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
4213 4206
 
4214 4207
 	dockerCmd(c, "run", "-i", "-d", "--name", "parent", "-v", fmt.Sprintf("%s:/volume-dest:slave", tmpDir), "busybox", "top")
4215 4208
 
4216 4209
 	// Bind mount tmpDir2/ onto tmpDir/mnt1. If mount propagates inside
4217 4210
 	// container then contents of tmpDir2/slave-testfile should become
4218 4211
 	// visible at "/volume-dest/mnt1/slave-testfile"
4219
-	cmd = exec.Command("mount", "--bind", tmpDir2, path.Join(tmpDir, "mnt1"))
4220
-	if _, err = runCommand(cmd); err != nil {
4221
-		c.Fatal(err)
4222
-	}
4212
+	icmd.RunCommand("mount", "--bind", tmpDir2, path.Join(tmpDir, "mnt1")).Assert(c, icmd.Success)
4223 4213
 
4224 4214
 	out, _ := dockerCmd(c, "exec", "parent", "cat", "/volume-dest/mnt1/slave-testfile")
4225 4215
 
... ...
@@ -4628,11 +4607,13 @@ func (s *DockerSuite) TestSlowStdinClosing(c *check.C) {
4628 4628
 	name := "testslowstdinclosing"
4629 4629
 	repeat := 3 // regression happened 50% of the time
4630 4630
 	for i := 0; i < repeat; i++ {
4631
-		cmd := exec.Command(dockerBinary, "run", "--rm", "--name", name, "-i", "busybox", "cat")
4632
-		cmd.Stdin = &delayedReader{}
4631
+		cmd := icmd.Cmd{
4632
+			Command: []string{dockerBinary, "run", "--rm", "--name", name, "-i", "busybox", "cat"},
4633
+			Stdin:   &delayedReader{},
4634
+		}
4633 4635
 		done := make(chan error, 1)
4634 4636
 		go func() {
4635
-			_, err := runCommand(cmd)
4637
+			err := icmd.RunCmd(cmd).Error
4636 4638
 			done <- err
4637 4639
 		}()
4638 4640
 
... ...
@@ -71,9 +71,7 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
71 71
 	c.Assert(err, checker.IsNil)
72 72
 	defer f.Close()
73 73
 
74
-	runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
75
-	out, _, _, err := runCommandWithStdoutStderr(runCmd)
76
-	c.Assert(err, checker.IsNil)
74
+	out, _ := dockerCmd(c, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
77 75
 	c.Assert(out, checker.Contains, filepath.Base(f.Name()), check.Commentf("Recursive bind mount test failed. Expected file not found"))
78 76
 }
79 77
 
... ...
@@ -14,6 +14,7 @@ import (
14 14
 	"time"
15 15
 
16 16
 	"github.com/docker/distribution/digest"
17
+	"github.com/docker/docker/pkg/integration"
17 18
 	"github.com/docker/docker/pkg/integration/checker"
18 19
 	"github.com/go-check/check"
19 20
 )
... ...
@@ -29,7 +30,7 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
29 29
 
30 30
 	dockerCmd(c, "inspect", repoName)
31 31
 
32
-	repoTarball, _, err := runCommandPipelineWithOutput(
32
+	repoTarball, _, err := integration.RunCommandPipelineWithOutput(
33 33
 		exec.Command(dockerBinary, "save", repoName),
34 34
 		exec.Command("xz", "-c"),
35 35
 		exec.Command("gzip", "-c"))
... ...
@@ -56,7 +57,7 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
56 56
 
57 57
 	dockerCmd(c, "inspect", repoName)
58 58
 
59
-	out, _, err := runCommandPipelineWithOutput(
59
+	out, _, err := integration.RunCommandPipelineWithOutput(
60 60
 		exec.Command(dockerBinary, "save", repoName),
61 61
 		exec.Command("xz", "-c"),
62 62
 		exec.Command("gzip", "-c"))
... ...
@@ -81,7 +82,7 @@ func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
81 81
 	out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName)
82 82
 	cleanedImageID := strings.TrimSpace(out)
83 83
 
84
-	out, _, err := runCommandPipelineWithOutput(
84
+	out, _, err := integration.RunCommandPipelineWithOutput(
85 85
 		exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
86 86
 		exec.Command("tar", "t"),
87 87
 		exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
... ...
@@ -100,7 +101,7 @@ func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
100 100
 	c.Assert(err, checker.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err))
101 101
 	c.Assert(len(data), checker.Not(checker.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName))
102 102
 	tarTvTimeFormat := "2006-01-02 15:04"
103
-	out, _, err = runCommandPipelineWithOutput(
103
+	out, _, err = integration.RunCommandPipelineWithOutput(
104 104
 		exec.Command(dockerBinary, "save", repoName),
105 105
 		exec.Command("tar", "tv"),
106 106
 		exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), digest.Digest(data[0].ID).Hex())))
... ...
@@ -158,7 +159,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
158 158
 
159 159
 	before, _ := dockerCmd(c, "inspect", repoName)
160 160
 
161
-	out, _, err := runCommandPipelineWithOutput(
161
+	out, _, err := integration.RunCommandPipelineWithOutput(
162 162
 		exec.Command(dockerBinary, "save", repoName),
163 163
 		exec.Command(dockerBinary, "load"))
164 164
 	c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
... ...
@@ -187,7 +188,7 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
187 187
 	// Make two images
188 188
 	dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
189 189
 
190
-	out, _, err := runCommandPipelineWithOutput(
190
+	out, _, err := integration.RunCommandPipelineWithOutput(
191 191
 		exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)),
192 192
 		exec.Command("tar", "xO", "repositories"),
193 193
 		exec.Command("grep", "-q", "-E", "(-one|-two)"),
... ...
@@ -219,7 +220,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
219 219
 	deleteImages(repoName)
220 220
 
221 221
 	// create the archive
222
-	out, _, err := runCommandPipelineWithOutput(
222
+	out, _, err := integration.RunCommandPipelineWithOutput(
223 223
 		exec.Command(dockerBinary, "save", repoName, "busybox:latest"),
224 224
 		exec.Command("tar", "t"))
225 225
 	c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple images: %s, %v", out, err))
... ...
@@ -266,7 +267,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
266 266
 		true)
267 267
 	c.Assert(err, checker.IsNil, check.Commentf("%v", err))
268 268
 
269
-	out, _, err := runCommandPipelineWithOutput(
269
+	out, _, err := integration.RunCommandPipelineWithOutput(
270 270
 		exec.Command(dockerBinary, "save", name),
271 271
 		exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
272 272
 	)
... ...
@@ -285,7 +286,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
285 285
 			c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err))
286 286
 			defer f.Close()
287 287
 
288
-			entries, err := listTar(f)
288
+			entries, err := integration.ListTar(f)
289 289
 			for _, e := range entries {
290 290
 				if !strings.Contains(e, "dev/") {
291 291
 					entriesSansDev = append(entriesSansDev, e)
... ...
@@ -363,7 +364,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
363 363
 	id := inspectField(c, name, "Id")
364 364
 
365 365
 	// Test to make sure that save w/o name just shows imageID during load
366
-	out, _, err := runCommandPipelineWithOutput(
366
+	out, _, err := integration.RunCommandPipelineWithOutput(
367 367
 		exec.Command(dockerBinary, "save", id),
368 368
 		exec.Command(dockerBinary, "load"))
369 369
 	c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
... ...
@@ -374,7 +375,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
374 374
 	c.Assert(out, checker.Contains, id)
375 375
 
376 376
 	// Test to make sure that save by name shows that name during load
377
-	out, _, err = runCommandPipelineWithOutput(
377
+	out, _, err = integration.RunCommandPipelineWithOutput(
378 378
 		exec.Command(dockerBinary, "save", name),
379 379
 		exec.Command(dockerBinary, "load"))
380 380
 	c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"time"
13 13
 
14 14
 	"github.com/docker/docker/pkg/integration/checker"
15
+	icmd "github.com/docker/docker/pkg/integration/cmd"
15 16
 	"github.com/go-check/check"
16 17
 	"github.com/kr/pty"
17 18
 )
... ...
@@ -29,11 +30,10 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
29 29
 	c.Assert(err, check.IsNil)
30 30
 	defer os.Remove(tmpFile.Name())
31 31
 
32
-	saveCmd := exec.Command(dockerBinary, "save", repoName)
33
-	saveCmd.Stdout = tmpFile
34
-
35
-	_, err = runCommand(saveCmd)
36
-	c.Assert(err, check.IsNil)
32
+	icmd.RunCmd(icmd.Cmd{
33
+		Command: []string{dockerBinary, "save", repoName},
34
+		Stdout:  tmpFile,
35
+	}).Assert(c, icmd.Success)
37 36
 
38 37
 	tmpFile, err = os.Open(tmpFile.Name())
39 38
 	c.Assert(err, check.IsNil)
... ...
@@ -2,11 +2,11 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os/exec"
6 5
 	"strings"
7 6
 	"time"
8 7
 
9 8
 	"github.com/docker/docker/pkg/integration/checker"
9
+	icmd "github.com/docker/docker/pkg/integration/cmd"
10 10
 	"github.com/go-check/check"
11 11
 )
12 12
 
... ...
@@ -182,8 +182,13 @@ func (s *DockerSuite) TestStartAttachWithRename(c *check.C) {
182 182
 		dockerCmd(c, "rename", "before", "after")
183 183
 		dockerCmd(c, "stop", "--time=2", "after")
184 184
 	}()
185
-	_, stderr, _, _ := runCommandWithStdoutStderr(exec.Command(dockerBinary, "start", "-a", "before"))
186
-	c.Assert(stderr, checker.Not(checker.Contains), "No such container")
185
+	// FIXME(vdemeester) the intent is not clear and potentially racey
186
+	result := icmd.RunCommand(dockerBinary, "start", "-a", "before")
187
+	result.Assert(c, icmd.Expected{
188
+		ExitCode: 137,
189
+		Error:    "exit status 137",
190
+	})
191
+	c.Assert(result.Stderr(), checker.Not(checker.Contains), "No such container")
187 192
 }
188 193
 
189 194
 func (s *DockerSuite) TestStartReturnCorrectExitCode(c *check.C) {
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"strconv"
13 13
 	"strings"
14 14
 
15
+	"github.com/docker/docker/pkg/integration"
15 16
 	"github.com/docker/docker/pkg/integration/checker"
16 17
 	"github.com/docker/docker/pkg/stringid"
17 18
 	"github.com/docker/docker/pkg/system"
... ...
@@ -61,12 +62,12 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
61 61
 	c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid))
62 62
 	// check the uid and gid maps for the PID to ensure root is remapped
63 63
 	// (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1')
64
-	out, rc1, err := runCommandPipelineWithOutput(
64
+	out, rc1, err := integration.RunCommandPipelineWithOutput(
65 65
 		exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/uid_map"),
66 66
 		exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", uid)))
67 67
 	c.Assert(rc1, checker.Equals, 0, check.Commentf("Didn't match uid_map: output: %s", out))
68 68
 
69
-	out, rc2, err := runCommandPipelineWithOutput(
69
+	out, rc2, err := integration.RunCommandPipelineWithOutput(
70 70
 		exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/gid_map"),
71 71
 		exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", gid)))
72 72
 	c.Assert(rc2, checker.Equals, 0, check.Commentf("Didn't match gid_map: output: %s", out))
... ...
@@ -16,8 +16,8 @@ import (
16 16
 func (s *DockerSuite) TestVolumeCLICreate(c *check.C) {
17 17
 	dockerCmd(c, "volume", "create")
18 18
 
19
-	_, err := runCommand(exec.Command(dockerBinary, "volume", "create", "-d", "nosuchdriver"))
20
-	c.Assert(err, check.Not(check.IsNil))
19
+	_, _, err := dockerCmdWithError("volume", "create", "-d", "nosuchdriver")
20
+	c.Assert(err, check.NotNil)
21 21
 
22 22
 	// test using hidden --name option
23 23
 	out, _ := dockerCmd(c, "volume", "create", "--name=test")
... ...
@@ -250,6 +250,7 @@ func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
250 250
 	)
251 251
 }
252 252
 
253
+// FIXME(vdemeester) should be a unit test in cli/command/volume package
253 254
 func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
254 255
 	out, _ := dockerCmd(c, "volume")
255 256
 	// no args should produce the cmd usage output
... ...
@@ -257,15 +258,20 @@ func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
257 257
 	c.Assert(out, checker.Contains, usage)
258 258
 
259 259
 	// invalid arg should error and show the command usage on stderr
260
-	_, stderr, _, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "somearg"))
261
-	c.Assert(err, check.NotNil, check.Commentf(stderr))
262
-	c.Assert(stderr, checker.Contains, usage)
260
+	icmd.RunCommand(dockerBinary, "volume", "somearg").Assert(c, icmd.Expected{
261
+		ExitCode: 1,
262
+		Error:    "exit status 1",
263
+		Err:      usage,
264
+	})
263 265
 
264 266
 	// invalid flag should error and show the flag error and cmd usage
265
-	_, stderr, _, err = runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "--no-such-flag"))
266
-	c.Assert(err, check.NotNil, check.Commentf(stderr))
267
-	c.Assert(stderr, checker.Contains, usage)
268
-	c.Assert(stderr, checker.Contains, "unknown flag: --no-such-flag")
267
+	result := icmd.RunCommand(dockerBinary, "volume", "--no-such-flag")
268
+	result.Assert(c, icmd.Expected{
269
+		ExitCode: 125,
270
+		Error:    "exit status 125",
271
+		Err:      usage,
272
+	})
273
+	c.Assert(result.Stderr(), checker.Contains, "unknown flag: --no-such-flag")
269 274
 }
270 275
 
271 276
 func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *check.C) {
... ...
@@ -45,7 +45,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) {
45 45
 	c.Assert(err, checker.IsNil)
46 46
 	c.Assert(status, checker.Equals, http.StatusCreated)
47 47
 
48
-	bindPath := randomTmpDirPath("test", daemonPlatform)
48
+	bindPath := integration.RandomTmpDirPath("test", daemonPlatform)
49 49
 	config = map[string]interface{}{
50 50
 		"Binds": []string{bindPath + ":" + path},
51 51
 	}
... ...
@@ -72,8 +72,8 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C)
72 72
 	c.Assert(err, checker.IsNil)
73 73
 	c.Assert(status, checker.Equals, http.StatusCreated)
74 74
 
75
-	bindPath1 := randomTmpDirPath("test1", daemonPlatform)
76
-	bindPath2 := randomTmpDirPath("test2", daemonPlatform)
75
+	bindPath1 := integration.RandomTmpDirPath("test1", daemonPlatform)
76
+	bindPath2 := integration.RandomTmpDirPath("test2", daemonPlatform)
77 77
 
78 78
 	config = map[string]interface{}{
79 79
 		"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
... ...
@@ -902,15 +902,17 @@ func buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...str
902 902
 
903 903
 func buildImageWithStdoutStderr(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, string, error) {
904 904
 	buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...)
905
-	stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd)
905
+	result := icmd.RunCmd(transformCmd(buildCmd))
906
+	err := result.Error
907
+	exitCode := result.ExitCode
906 908
 	if err != nil || exitCode != 0 {
907
-		return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout)
909
+		return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
908 910
 	}
909 911
 	id, err := getIDByName(name)
910 912
 	if err != nil {
911
-		return "", stdout, stderr, err
913
+		return "", result.Stdout(), result.Stderr(), err
912 914
 	}
913
-	return id, stdout, stderr, nil
915
+	return id, result.Stdout(), result.Stderr(), nil
914 916
 }
915 917
 
916 918
 func buildImage(name, dockerfile string, useCache bool, buildFlags ...string) (string, error) {
... ...
@@ -953,18 +955,21 @@ func buildImageFromContextWithStdoutStderr(name string, ctx *FakeContext, useCac
953 953
 	}
954 954
 	args = append(args, buildFlags...)
955 955
 	args = append(args, ".")
956
-	buildCmd := exec.Command(dockerBinary, args...)
957
-	buildCmd.Dir = ctx.Dir
958 956
 
959
-	stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd)
957
+	result := icmd.RunCmd(icmd.Cmd{
958
+		Command: append([]string{dockerBinary}, args...),
959
+		Dir:     ctx.Dir,
960
+	})
961
+	exitCode := result.ExitCode
962
+	err := result.Error
960 963
 	if err != nil || exitCode != 0 {
961
-		return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout)
964
+		return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
962 965
 	}
963 966
 	id, err := getIDByName(name)
964 967
 	if err != nil {
965
-		return "", stdout, stderr, err
968
+		return "", result.Stdout(), result.Stderr(), err
966 969
 	}
967
-	return id, stdout, stderr, nil
970
+	return id, result.Stdout(), result.Stderr(), nil
968 971
 }
969 972
 
970 973
 func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool, buildFlags ...string) (string, string, string, error) {
... ...
@@ -974,17 +979,19 @@ func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool,
974 974
 	}
975 975
 	args = append(args, buildFlags...)
976 976
 	args = append(args, ctx.RepoURL)
977
-	buildCmd := exec.Command(dockerBinary, args...)
978
-
979
-	stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd)
977
+	result := icmd.RunCmd(icmd.Cmd{
978
+		Command: append([]string{dockerBinary}, args...),
979
+	})
980
+	exitCode := result.ExitCode
981
+	err := result.Error
980 982
 	if err != nil || exitCode != 0 {
981
-		return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout)
983
+		return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
982 984
 	}
983 985
 	id, err := getIDByName(name)
984 986
 	if err != nil {
985
-		return "", stdout, stderr, err
987
+		return "", result.Stdout(), result.Stderr(), err
986 988
 	}
987
-	return id, stdout, stderr, nil
989
+	return id, result.Stdout(), result.Stderr(), nil
988 990
 }
989 991
 
990 992
 func buildImageFromPath(name, path string, useCache bool, buildFlags ...string) (string, error) {
... ...
@@ -1,13 +1,8 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"io"
5
-	"os"
6
-	"os/exec"
7
-	"time"
8
-
9
-	"github.com/docker/docker/pkg/integration"
10 4
 	"github.com/docker/docker/pkg/integration/cmd"
5
+	"os/exec"
11 6
 )
12 7
 
13 8
 func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {
... ...
@@ -23,18 +18,6 @@ func runCommandWithOutput(execCmd *exec.Cmd) (string, int, error) {
23 23
 	return result.Combined(), result.ExitCode, result.Error
24 24
 }
25 25
 
26
-// TODO: update code to call cmd.RunCmd directly, and remove this function
27
-func runCommandWithStdoutStderr(execCmd *exec.Cmd) (string, string, int, error) {
28
-	result := cmd.RunCmd(transformCmd(execCmd))
29
-	return result.Stdout(), result.Stderr(), result.ExitCode, result.Error
30
-}
31
-
32
-// TODO: update code to call cmd.RunCmd directly, and remove this function
33
-func runCommand(execCmd *exec.Cmd) (exitCode int, err error) {
34
-	result := cmd.RunCmd(transformCmd(execCmd))
35
-	return result.ExitCode, result.Error
36
-}
37
-
38 26
 // Temporary shim for migrating commands to the new function
39 27
 func transformCmd(execCmd *exec.Cmd) cmd.Cmd {
40 28
 	return cmd.Cmd{
... ...
@@ -45,35 +28,3 @@ func transformCmd(execCmd *exec.Cmd) cmd.Cmd {
45 45
 		Stdout:  execCmd.Stdout,
46 46
 	}
47 47
 }
48
-
49
-func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode int, err error) {
50
-	return integration.RunCommandPipelineWithOutput(cmds...)
51
-}
52
-
53
-func convertSliceOfStringsToMap(input []string) map[string]struct{} {
54
-	return integration.ConvertSliceOfStringsToMap(input)
55
-}
56
-
57
-func compareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error {
58
-	return integration.CompareDirectoryEntries(e1, e2)
59
-}
60
-
61
-func listTar(f io.Reader) ([]string, error) {
62
-	return integration.ListTar(f)
63
-}
64
-
65
-func randomTmpDirPath(s string, platform string) string {
66
-	return integration.RandomTmpDirPath(s, platform)
67
-}
68
-
69
-func consumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) {
70
-	return integration.ConsumeWithSpeed(reader, chunkSize, interval, stop)
71
-}
72
-
73
-func parseCgroupPaths(procCgroupData string) map[string]string {
74
-	return integration.ParseCgroupPaths(procCgroupData)
75
-}
76
-
77
-func runAtDifferentDate(date time.Time, block func()) {
78
-	integration.RunAtDifferentDate(date, block)
79
-}