These replace `wait*` functions from `docker_utils_test.go` and work
more or less like other `cli` functions.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
... | ... |
@@ -58,6 +58,58 @@ func InspectCmd(t testingT, name string, cmdOperators ...CmdOperator) *icmd.Resu |
58 | 58 |
return Docker(Inspect(name), cmdOperators...).Assert(t, icmd.Success) |
59 | 59 |
} |
60 | 60 |
|
61 |
+// WaitRun will wait for the specified container to be running, maximum 5 seconds. |
|
62 |
+func WaitRun(t testingT, name string, cmdOperators ...CmdOperator) { |
|
63 |
+ WaitForInspectResult(t, name, "{{.State.Running}}", "true", 5*time.Second, cmdOperators...) |
|
64 |
+} |
|
65 |
+ |
|
66 |
+// WaitExited will wait for the specified container to state exit, subject |
|
67 |
+// to a maximum time limit in seconds supplied by the caller |
|
68 |
+func WaitExited(t testingT, name string, timeout time.Duration, cmdOperators ...CmdOperator) { |
|
69 |
+ WaitForInspectResult(t, name, "{{.State.Status}}", "exited", timeout, cmdOperators...) |
|
70 |
+} |
|
71 |
+ |
|
72 |
+// WaitRestart will wait for the specified container to restart once |
|
73 |
+func WaitRestart(t testingT, name string, timeout time.Duration, cmdOperators ...CmdOperator) { |
|
74 |
+ WaitForInspectResult(t, name, "{{.RestartCount}}", "1", timeout, cmdOperators...) |
|
75 |
+} |
|
76 |
+ |
|
77 |
+// WaitForInspectResult waits for the specified expression to be equals to the specified expected string in the given time. |
|
78 |
+func WaitForInspectResult(t testingT, name, expr, expected string, timeout time.Duration, cmdOperators ...CmdOperator) { |
|
79 |
+ after := time.After(timeout) |
|
80 |
+ |
|
81 |
+ args := []string{"inspect", "-f", expr, name} |
|
82 |
+ for { |
|
83 |
+ result := Docker(Args(args...), cmdOperators...) |
|
84 |
+ if result.Error != nil { |
|
85 |
+ if !strings.Contains(strings.ToLower(result.Stderr()), "no such") { |
|
86 |
+ t.Fatalf("error executing docker inspect: %v\n%s", |
|
87 |
+ result.Stderr(), result.Stdout()) |
|
88 |
+ } |
|
89 |
+ select { |
|
90 |
+ case <-after: |
|
91 |
+ t.Fatal(result.Error) |
|
92 |
+ default: |
|
93 |
+ time.Sleep(10 * time.Millisecond) |
|
94 |
+ continue |
|
95 |
+ } |
|
96 |
+ } |
|
97 |
+ |
|
98 |
+ out := strings.TrimSpace(result.Stdout()) |
|
99 |
+ if out == expected { |
|
100 |
+ break |
|
101 |
+ } |
|
102 |
+ |
|
103 |
+ select { |
|
104 |
+ case <-after: |
|
105 |
+ t.Fatalf("condition \"%q == %q\" not true in time (%v)", out, expected, timeout) |
|
106 |
+ default: |
|
107 |
+ } |
|
108 |
+ |
|
109 |
+ time.Sleep(100 * time.Millisecond) |
|
110 |
+ } |
|
111 |
+} |
|
112 |
+ |
|
61 | 113 |
// Docker executes the specified docker command |
62 | 114 |
func Docker(cmd icmd.Cmd, cmdOperators ...CmdOperator) *icmd.Result { |
63 | 115 |
for _, op := range cmdOperators { |
... | ... |
@@ -758,7 +758,7 @@ func (d *Daemon) ReloadConfig() error { |
758 | 758 |
} |
759 | 759 |
|
760 | 760 |
// WaitInspectWithArgs waits for the specified expression to be equals to the specified expected string in the given time. |
761 |
-// FIXME(vdemeester) Attach this to the Daemon struct |
|
761 |
+// Deprecated: use cli.WaitCmd instead |
|
762 | 762 |
func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time.Duration, arg ...string) error { |
763 | 763 |
after := time.After(timeout) |
764 | 764 |
|
... | ... |
@@ -10,6 +10,7 @@ import ( |
10 | 10 |
"sync" |
11 | 11 |
"time" |
12 | 12 |
|
13 |
+ "github.com/docker/docker/integration-cli/cli" |
|
13 | 14 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
14 | 15 |
"github.com/go-check/check" |
15 | 16 |
) |
... | ... |
@@ -22,8 +23,8 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) { |
22 | 22 |
endGroup.Add(3) |
23 | 23 |
startGroup.Add(3) |
24 | 24 |
|
25 |
- err := waitForContainer("attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done") |
|
26 |
- c.Assert(err, check.IsNil) |
|
25 |
+ cli.DockerCmd(c, "run", "--name", "attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done") |
|
26 |
+ cli.WaitRun(c, "attacher") |
|
27 | 27 |
|
28 | 28 |
startDone := make(chan struct{}) |
29 | 29 |
endDone := make(chan struct{}) |
... | ... |
@@ -77,7 +78,7 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) { |
77 | 77 |
c.Fatalf("Attaches did not initialize properly") |
78 | 78 |
} |
79 | 79 |
|
80 |
- dockerCmd(c, "kill", "attacher") |
|
80 |
+ cli.DockerCmd(c, "kill", "attacher") |
|
81 | 81 |
|
82 | 82 |
select { |
83 | 83 |
case <-endDone: |
... | ... |
@@ -5,13 +5,14 @@ import ( |
5 | 5 |
"time" |
6 | 6 |
|
7 | 7 |
"github.com/docker/docker/integration-cli/checker" |
8 |
+ "github.com/docker/docker/integration-cli/cli" |
|
8 | 9 |
"github.com/go-check/check" |
9 | 10 |
) |
10 | 11 |
|
11 | 12 |
// ensure that an added file shows up in docker diff |
12 | 13 |
func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) { |
13 | 14 |
containerCmd := `mkdir /foo; echo xyzzy > /foo/bar` |
14 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd) |
|
15 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd).Combined() |
|
15 | 16 |
|
16 | 17 |
// Wait for it to exit as cannot diff a running container on Windows, and |
17 | 18 |
// it will take a few seconds to exit. Also there's no way in Windows to |
... | ... |
@@ -20,13 +21,12 @@ func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) { |
20 | 20 |
containerID := strings.TrimSpace(out) |
21 | 21 |
lookingFor := "A /foo/bar" |
22 | 22 |
if testEnv.DaemonPlatform() == "windows" { |
23 |
- err := waitExited(containerID, 60*time.Second) |
|
24 |
- c.Assert(err, check.IsNil) |
|
23 |
+ cli.WaitExited(c, containerID, 60*time.Second) |
|
25 | 24 |
lookingFor = "C Files/foo/bar" |
26 | 25 |
} |
27 | 26 |
|
28 | 27 |
cleanCID := strings.TrimSpace(out) |
29 |
- out, _ = dockerCmd(c, "diff", cleanCID) |
|
28 |
+ out = cli.DockerCmd(c, "diff", cleanCID).Combined() |
|
30 | 29 |
|
31 | 30 |
found := false |
32 | 31 |
for _, line := range strings.Split(out, "\n") { |
... | ... |
@@ -15,6 +15,7 @@ import ( |
15 | 15 |
eventtypes "github.com/docker/docker/api/types/events" |
16 | 16 |
eventstestutils "github.com/docker/docker/daemon/events/testutils" |
17 | 17 |
"github.com/docker/docker/integration-cli/checker" |
18 |
+ "github.com/docker/docker/integration-cli/cli" |
|
18 | 19 |
"github.com/docker/docker/integration-cli/cli/build" |
19 | 20 |
"github.com/docker/docker/integration-cli/request" |
20 | 21 |
"github.com/docker/docker/pkg/testutil" |
... | ... |
@@ -453,14 +454,14 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) { |
453 | 453 |
|
454 | 454 |
out, _ := runSleepingContainer(c) |
455 | 455 |
cID := strings.TrimSpace(out) |
456 |
- c.Assert(waitRun(cID), checker.IsNil) |
|
456 |
+ cli.WaitRun(c, cID) |
|
457 | 457 |
|
458 |
- dockerCmd(c, "commit", "-m", "test", cID) |
|
459 |
- dockerCmd(c, "stop", cID) |
|
460 |
- c.Assert(waitExited(cID, 5*time.Second), checker.IsNil) |
|
458 |
+ cli.DockerCmd(c, "commit", "-m", "test", cID) |
|
459 |
+ cli.DockerCmd(c, "stop", cID) |
|
460 |
+ cli.WaitExited(c, cID, 5*time.Second) |
|
461 | 461 |
|
462 | 462 |
until := daemonUnixTime(c) |
463 |
- out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) |
|
463 |
+ out = cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined() |
|
464 | 464 |
c.Assert(out, checker.Contains, "commit", check.Commentf("Missing 'commit' log event")) |
465 | 465 |
} |
466 | 466 |
|
... | ... |
@@ -514,9 +515,9 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) { |
514 | 514 |
// TODO Windows CI: Figure out why this test fails intermittently (TP5). |
515 | 515 |
testRequires(c, DaemonIsLinux) |
516 | 516 |
|
517 |
- out, _ := dockerCmd(c, "run", "-di", "busybox", "cat") |
|
517 |
+ out := cli.DockerCmd(c, "run", "-di", "busybox", "cat").Combined() |
|
518 | 518 |
cID := strings.TrimSpace(out) |
519 |
- c.Assert(waitRun(cID), checker.IsNil) |
|
519 |
+ cli.WaitRun(c, cID) |
|
520 | 520 |
|
521 | 521 |
cmd := exec.Command(dockerBinary, "attach", cID) |
522 | 522 |
stdin, err := cmd.StdinPipe() |
... | ... |
@@ -537,11 +538,11 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) { |
537 | 537 |
|
538 | 538 |
c.Assert(stdin.Close(), checker.IsNil) |
539 | 539 |
|
540 |
- dockerCmd(c, "kill", cID) |
|
541 |
- c.Assert(waitExited(cID, 5*time.Second), checker.IsNil) |
|
540 |
+ cli.DockerCmd(c, "kill", cID) |
|
541 |
+ cli.WaitExited(c, cID, 5*time.Second) |
|
542 | 542 |
|
543 | 543 |
until := daemonUnixTime(c) |
544 |
- out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) |
|
544 |
+ out = cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined() |
|
545 | 545 |
c.Assert(out, checker.Contains, "attach", check.Commentf("Missing 'attach' log event")) |
546 | 546 |
} |
547 | 547 |
|
... | ... |
@@ -16,11 +16,11 @@ import ( |
16 | 16 |
"time" |
17 | 17 |
|
18 | 18 |
"github.com/docker/docker/integration-cli/checker" |
19 |
+ "github.com/docker/docker/integration-cli/cli" |
|
19 | 20 |
"github.com/docker/docker/integration-cli/cli/build" |
20 | 21 |
"github.com/docker/docker/integration-cli/request" |
21 | 22 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
22 | 23 |
"github.com/go-check/check" |
23 |
- "github.com/docker/docker/integration-cli/cli" |
|
24 | 24 |
) |
25 | 25 |
|
26 | 26 |
func (s *DockerSuite) TestExec(c *check.C) { |
... | ... |
@@ -7,19 +7,21 @@ import ( |
7 | 7 |
"time" |
8 | 8 |
|
9 | 9 |
"github.com/docker/docker/integration-cli/checker" |
10 |
+ "github.com/docker/docker/integration-cli/cli" |
|
10 | 11 |
"github.com/docker/docker/integration-cli/request" |
12 |
+ icmd "github.com/docker/docker/pkg/testutil/cmd" |
|
11 | 13 |
"github.com/go-check/check" |
12 | 14 |
) |
13 | 15 |
|
14 | 16 |
func (s *DockerSuite) TestKillContainer(c *check.C) { |
15 | 17 |
out, _ := runSleepingContainer(c, "-d") |
16 | 18 |
cleanedContainerID := strings.TrimSpace(out) |
17 |
- c.Assert(waitRun(cleanedContainerID), check.IsNil) |
|
19 |
+ cli.WaitRun(c, cleanedContainerID) |
|
18 | 20 |
|
19 |
- dockerCmd(c, "kill", cleanedContainerID) |
|
20 |
- c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil) |
|
21 |
+ cli.DockerCmd(c, "kill", cleanedContainerID) |
|
22 |
+ cli.WaitExited(c, cleanedContainerID, 10*time.Second) |
|
21 | 23 |
|
22 |
- out, _ = dockerCmd(c, "ps", "-q") |
|
24 |
+ out = cli.DockerCmd(c, "ps", "-q").Combined() |
|
23 | 25 |
c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running")) |
24 | 26 |
|
25 | 27 |
} |
... | ... |
@@ -28,24 +30,25 @@ func (s *DockerSuite) TestKillOffStoppedContainer(c *check.C) { |
28 | 28 |
out, _ := runSleepingContainer(c, "-d") |
29 | 29 |
cleanedContainerID := strings.TrimSpace(out) |
30 | 30 |
|
31 |
- dockerCmd(c, "stop", cleanedContainerID) |
|
32 |
- c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil) |
|
31 |
+ cli.DockerCmd(c, "stop", cleanedContainerID) |
|
32 |
+ cli.WaitExited(c, cleanedContainerID, 10*time.Second) |
|
33 | 33 |
|
34 |
- _, _, err := dockerCmdWithError("kill", "-s", "30", cleanedContainerID) |
|
35 |
- c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID)) |
|
34 |
+ cli.Docker(cli.Args("kill", "-s", "30", cleanedContainerID)).Assert(c, icmd.Expected{ |
|
35 |
+ ExitCode: 1, |
|
36 |
+ }) |
|
36 | 37 |
} |
37 | 38 |
|
38 | 39 |
func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) { |
39 | 40 |
// TODO Windows: Windows does not yet support -u (Feb 2016). |
40 | 41 |
testRequires(c, DaemonIsLinux) |
41 |
- out, _ := dockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top") |
|
42 |
+ out := cli.DockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top").Combined() |
|
42 | 43 |
cleanedContainerID := strings.TrimSpace(out) |
43 |
- c.Assert(waitRun(cleanedContainerID), check.IsNil) |
|
44 |
+ cli.WaitRun(c, cleanedContainerID) |
|
44 | 45 |
|
45 |
- dockerCmd(c, "kill", cleanedContainerID) |
|
46 |
- c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil) |
|
46 |
+ cli.DockerCmd(c, "kill", cleanedContainerID) |
|
47 |
+ cli.WaitExited(c, cleanedContainerID, 10*time.Second) |
|
47 | 48 |
|
48 |
- out, _ = dockerCmd(c, "ps", "-q") |
|
49 |
+ out = cli.DockerCmd(c, "ps", "-q").Combined() |
|
49 | 50 |
c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running")) |
50 | 51 |
|
51 | 52 |
} |
... | ... |
@@ -69,33 +72,33 @@ func (s *DockerSuite) TestKillWithSignal(c *check.C) { |
69 | 69 |
func (s *DockerSuite) TestKillWithStopSignalWithSameSignalShouldDisableRestartPolicy(c *check.C) { |
70 | 70 |
// Cannot port to Windows - does not support signals int the same way as Linux does |
71 | 71 |
testRequires(c, DaemonIsLinux) |
72 |
- out, _ := dockerCmd(c, "run", "-d", "--stop-signal=TERM", "--restart=always", "busybox", "top") |
|
72 |
+ out := cli.DockerCmd(c, "run", "-d", "--stop-signal=TERM", "--restart=always", "busybox", "top").Combined() |
|
73 | 73 |
cid := strings.TrimSpace(out) |
74 |
- c.Assert(waitRun(cid), check.IsNil) |
|
74 |
+ cli.WaitRun(c, cid) |
|
75 | 75 |
|
76 | 76 |
// Let docker send a TERM signal to the container |
77 | 77 |
// It will kill the process and disable the restart policy |
78 |
- dockerCmd(c, "kill", "-s", "TERM", cid) |
|
79 |
- c.Assert(waitExited(cid, 10*time.Second), check.IsNil) |
|
78 |
+ cli.DockerCmd(c, "kill", "-s", "TERM", cid) |
|
79 |
+ cli.WaitExited(c, cid, 10*time.Second) |
|
80 | 80 |
|
81 |
- out, _ = dockerCmd(c, "ps", "-q") |
|
81 |
+ out = cli.DockerCmd(c, "ps", "-q").Combined() |
|
82 | 82 |
c.Assert(out, checker.Not(checker.Contains), cid, check.Commentf("killed container is still running")) |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
func (s *DockerSuite) TestKillWithStopSignalWithDifferentSignalShouldKeepRestartPolicy(c *check.C) { |
86 | 86 |
// Cannot port to Windows - does not support signals int the same way as Linux does |
87 | 87 |
testRequires(c, DaemonIsLinux) |
88 |
- out, _ := dockerCmd(c, "run", "-d", "--stop-signal=CONT", "--restart=always", "busybox", "top") |
|
88 |
+ out := cli.DockerCmd(c, "run", "-d", "--stop-signal=CONT", "--restart=always", "busybox", "top").Combined() |
|
89 | 89 |
cid := strings.TrimSpace(out) |
90 |
- c.Assert(waitRun(cid), check.IsNil) |
|
90 |
+ cli.WaitRun(c, cid) |
|
91 | 91 |
|
92 | 92 |
// Let docker send a TERM signal to the container |
93 | 93 |
// It will kill the process, but not disable the restart policy |
94 |
- dockerCmd(c, "kill", "-s", "TERM", cid) |
|
95 |
- c.Assert(waitRestart(cid, 10*time.Second), check.IsNil) |
|
94 |
+ cli.DockerCmd(c, "kill", "-s", "TERM", cid) |
|
95 |
+ cli.WaitRestart(c, cid, 10*time.Second) |
|
96 | 96 |
|
97 | 97 |
// Restart policy should still be in place, so it should be still running |
98 |
- c.Assert(waitRun(cid), check.IsNil) |
|
98 |
+ cli.WaitRun(c, cid) |
|
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
// FIXME(vdemeester) should be a unit test |
... | ... |
@@ -7,18 +7,23 @@ import ( |
7 | 7 |
"strings" |
8 | 8 |
|
9 | 9 |
"github.com/docker/docker/integration-cli/checker" |
10 |
+ "github.com/docker/docker/integration-cli/cli" |
|
10 | 11 |
"github.com/go-check/check" |
11 | 12 |
) |
12 | 13 |
|
13 | 14 |
func startServerContainer(c *check.C, msg string, port int) string { |
14 | 15 |
name := "server" |
15 | 16 |
cmd := []string{ |
17 |
+ "run", |
|
18 |
+ "--name", |
|
19 |
+ name, |
|
16 | 20 |
"-d", |
17 | 21 |
"-p", fmt.Sprintf("%d:%d", port, port), |
18 | 22 |
"busybox", |
19 | 23 |
"sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port), |
20 | 24 |
} |
21 |
- c.Assert(waitForContainer(name, cmd...), check.IsNil) |
|
25 |
+ cli.DockerCmd(c, cmd...) |
|
26 |
+ cli.WaitRun(c, name) |
|
22 | 27 |
return name |
23 | 28 |
} |
24 | 29 |
|
... | ... |
@@ -18,6 +18,7 @@ import ( |
18 | 18 |
"github.com/docker/docker/api/types" |
19 | 19 |
"github.com/docker/docker/api/types/versions/v1p20" |
20 | 20 |
"github.com/docker/docker/integration-cli/checker" |
21 |
+ "github.com/docker/docker/integration-cli/cli" |
|
21 | 22 |
"github.com/docker/docker/integration-cli/daemon" |
22 | 23 |
"github.com/docker/docker/pkg/stringid" |
23 | 24 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
... | ... |
@@ -1797,18 +1798,16 @@ func (s *DockerNetworkSuite) TestConntrackFlowsLeak(c *check.C) { |
1797 | 1797 |
testRequires(c, IsAmd64, DaemonIsLinux, Network) |
1798 | 1798 |
|
1799 | 1799 |
// Create a new network |
1800 |
- dockerCmd(c, "network", "create", "--subnet=192.168.10.0/24", "--gateway=192.168.10.1", "-o", "com.docker.network.bridge.host_binding_ipv4=192.168.10.1", "testbind") |
|
1800 |
+ cli.DockerCmd(c, "network", "create", "--subnet=192.168.10.0/24", "--gateway=192.168.10.1", "-o", "com.docker.network.bridge.host_binding_ipv4=192.168.10.1", "testbind") |
|
1801 | 1801 |
assertNwIsAvailable(c, "testbind") |
1802 | 1802 |
|
1803 | 1803 |
// Launch the server, this will remain listening on an exposed port and reply to any request in a ping/pong fashion |
1804 | 1804 |
cmd := "while true; do echo hello | nc -w 1 -lu 8080; done" |
1805 |
- _, _, err := dockerCmdWithError("run", "-d", "--name", "server", "--net", "testbind", "-p", "8080:8080/udp", "appropriate/nc", "sh", "-c", cmd) |
|
1806 |
- c.Assert(err, check.IsNil) |
|
1805 |
+ cli.DockerCmd(c, "run", "-d", "--name", "server", "--net", "testbind", "-p", "8080:8080/udp", "appropriate/nc", "sh", "-c", cmd) |
|
1807 | 1806 |
|
1808 | 1807 |
// Launch a container client, here the objective is to create a flow that is natted in order to expose the bug |
1809 | 1808 |
cmd = "echo world | nc -q 1 -u 192.168.10.1 8080" |
1810 |
- _, _, err = dockerCmdWithError("run", "-d", "--name", "client", "--net=host", "appropriate/nc", "sh", "-c", cmd) |
|
1811 |
- c.Assert(err, check.IsNil) |
|
1809 |
+ cli.DockerCmd(c, "run", "-d", "--name", "client", "--net=host", "appropriate/nc", "sh", "-c", cmd) |
|
1812 | 1810 |
|
1813 | 1811 |
// Get all the flows using netlink |
1814 | 1812 |
flows, err := netlink.ConntrackTableList(netlink.ConntrackTable, syscall.AF_INET) |
... | ... |
@@ -1826,8 +1825,7 @@ func (s *DockerNetworkSuite) TestConntrackFlowsLeak(c *check.C) { |
1826 | 1826 |
c.Assert(flowMatch, checker.Equals, 1) |
1827 | 1827 |
|
1828 | 1828 |
// Now delete the server, this will trigger the conntrack cleanup |
1829 |
- err = deleteContainer("server") |
|
1830 |
- c.Assert(err, checker.IsNil) |
|
1829 |
+ cli.DockerCmd(c, "rm", "-fv", "server") |
|
1831 | 1830 |
|
1832 | 1831 |
// Fetch again all the flows and validate that there is no server flow in the conntrack laying around |
1833 | 1832 |
flows, err = netlink.ConntrackTableList(netlink.ConntrackTable, syscall.AF_INET) |
... | ... |
@@ -11,6 +11,7 @@ import ( |
11 | 11 |
"time" |
12 | 12 |
|
13 | 13 |
"github.com/docker/docker/integration-cli/checker" |
14 |
+ "github.com/docker/docker/integration-cli/cli" |
|
14 | 15 |
"github.com/docker/docker/integration-cli/daemon" |
15 | 16 |
"github.com/go-check/check" |
16 | 17 |
) |
... | ... |
@@ -96,41 +97,41 @@ func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) { |
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
func (s *DockerSuite) TestPruneContainerUntil(c *check.C) { |
99 |
- out, _ := dockerCmd(c, "run", "-d", "busybox") |
|
99 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox").Combined() |
|
100 | 100 |
id1 := strings.TrimSpace(out) |
101 |
- c.Assert(waitExited(id1, 5*time.Second), checker.IsNil) |
|
101 |
+ cli.WaitExited(c, id1, 5*time.Second) |
|
102 | 102 |
|
103 | 103 |
until := daemonUnixTime(c) |
104 | 104 |
|
105 |
- out, _ = dockerCmd(c, "run", "-d", "busybox") |
|
105 |
+ out = cli.DockerCmd(c, "run", "-d", "busybox").Combined() |
|
106 | 106 |
id2 := strings.TrimSpace(out) |
107 |
- c.Assert(waitExited(id2, 5*time.Second), checker.IsNil) |
|
107 |
+ cli.WaitExited(c, id2, 5*time.Second) |
|
108 | 108 |
|
109 |
- out, _ = dockerCmd(c, "container", "prune", "--force", "--filter", "until="+until) |
|
109 |
+ out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "until="+until).Combined() |
|
110 | 110 |
c.Assert(strings.TrimSpace(out), checker.Contains, id1) |
111 | 111 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2) |
112 | 112 |
|
113 |
- out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc") |
|
113 |
+ out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined() |
|
114 | 114 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1) |
115 | 115 |
c.Assert(strings.TrimSpace(out), checker.Contains, id2) |
116 | 116 |
} |
117 | 117 |
|
118 | 118 |
func (s *DockerSuite) TestPruneContainerLabel(c *check.C) { |
119 |
- out, _ := dockerCmd(c, "run", "-d", "--label", "foo", "busybox") |
|
119 |
+ out := cli.DockerCmd(c, "run", "-d", "--label", "foo", "busybox").Combined() |
|
120 | 120 |
id1 := strings.TrimSpace(out) |
121 |
- c.Assert(waitExited(id1, 5*time.Second), checker.IsNil) |
|
121 |
+ cli.WaitExited(c, id1, 5*time.Second) |
|
122 | 122 |
|
123 |
- out, _ = dockerCmd(c, "run", "-d", "--label", "bar", "busybox") |
|
123 |
+ out = cli.DockerCmd(c, "run", "-d", "--label", "bar", "busybox").Combined() |
|
124 | 124 |
id2 := strings.TrimSpace(out) |
125 |
- c.Assert(waitExited(id2, 5*time.Second), checker.IsNil) |
|
125 |
+ cli.WaitExited(c, id2, 5*time.Second) |
|
126 | 126 |
|
127 |
- out, _ = dockerCmd(c, "run", "-d", "busybox") |
|
127 |
+ out = cli.DockerCmd(c, "run", "-d", "busybox").Combined() |
|
128 | 128 |
id3 := strings.TrimSpace(out) |
129 |
- c.Assert(waitExited(id3, 5*time.Second), checker.IsNil) |
|
129 |
+ cli.WaitExited(c, id3, 5*time.Second) |
|
130 | 130 |
|
131 |
- out, _ = dockerCmd(c, "run", "-d", "--label", "foobar", "busybox") |
|
131 |
+ out = cli.DockerCmd(c, "run", "-d", "--label", "foobar", "busybox").Combined() |
|
132 | 132 |
id4 := strings.TrimSpace(out) |
133 |
- c.Assert(waitExited(id4, 5*time.Second), checker.IsNil) |
|
133 |
+ cli.WaitExited(c, id4, 5*time.Second) |
|
134 | 134 |
|
135 | 135 |
// Add a config file of label=foobar, that will have no impact if cli is label!=foobar |
136 | 136 |
config := `{"pruneFilters": ["label=foobar"]}` |
... | ... |
@@ -141,35 +142,35 @@ func (s *DockerSuite) TestPruneContainerLabel(c *check.C) { |
141 | 141 |
c.Assert(err, checker.IsNil) |
142 | 142 |
|
143 | 143 |
// With config.json only, prune based on label=foobar |
144 |
- out, _ = dockerCmd(c, "--config", d, "container", "prune", "--force") |
|
144 |
+ out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force").Combined() |
|
145 | 145 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1) |
146 | 146 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2) |
147 | 147 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3) |
148 | 148 |
c.Assert(strings.TrimSpace(out), checker.Contains, id4) |
149 | 149 |
|
150 |
- out, _ = dockerCmd(c, "container", "prune", "--force", "--filter", "label=foo") |
|
150 |
+ out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label=foo").Combined() |
|
151 | 151 |
c.Assert(strings.TrimSpace(out), checker.Contains, id1) |
152 | 152 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2) |
153 | 153 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3) |
154 | 154 |
|
155 |
- out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc") |
|
155 |
+ out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined() |
|
156 | 156 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1) |
157 | 157 |
c.Assert(strings.TrimSpace(out), checker.Contains, id2) |
158 | 158 |
c.Assert(strings.TrimSpace(out), checker.Contains, id3) |
159 | 159 |
|
160 |
- out, _ = dockerCmd(c, "container", "prune", "--force", "--filter", "label!=bar") |
|
160 |
+ out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label!=bar").Combined() |
|
161 | 161 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2) |
162 | 162 |
c.Assert(strings.TrimSpace(out), checker.Contains, id3) |
163 | 163 |
|
164 |
- out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc") |
|
164 |
+ out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined() |
|
165 | 165 |
c.Assert(strings.TrimSpace(out), checker.Contains, id2) |
166 | 166 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3) |
167 | 167 |
|
168 | 168 |
// With config.json label=foobar and CLI label!=foobar, CLI label!=foobar supersede |
169 |
- out, _ = dockerCmd(c, "--config", d, "container", "prune", "--force", "--filter", "label!=foobar") |
|
169 |
+ out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force", "--filter", "label!=foobar").Combined() |
|
170 | 170 |
c.Assert(strings.TrimSpace(out), checker.Contains, id2) |
171 | 171 |
|
172 |
- out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc") |
|
172 |
+ out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined() |
|
173 | 173 |
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2) |
174 | 174 |
} |
175 | 175 |
|
... | ... |
@@ -231,9 +231,9 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) { |
231 | 231 |
out, _ := runSleepingContainer(c, "--name=none_legacy") |
232 | 232 |
containerID := strings.TrimSpace(out) |
233 | 233 |
|
234 |
- waitForContainer(containerID) |
|
234 |
+ cli.WaitRun(c, containerID) |
|
235 | 235 |
|
236 |
- out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none") |
|
236 |
+ out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined() |
|
237 | 237 |
containerOut := strings.TrimSpace(out) |
238 | 238 |
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out)) |
239 | 239 |
|
... | ... |
@@ -241,9 +241,9 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) { |
241 | 241 |
out, _ = runSleepingContainer(c, "--name=none", "--no-healthcheck") |
242 | 242 |
containerID = strings.TrimSpace(out) |
243 | 243 |
|
244 |
- waitForContainer(containerID) |
|
244 |
+ cli.WaitRun(c, containerID) |
|
245 | 245 |
|
246 |
- out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none") |
|
246 |
+ out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined() |
|
247 | 247 |
containerOut = strings.TrimSpace(out) |
248 | 248 |
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out)) |
249 | 249 |
|
... | ... |
@@ -253,7 +253,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) { |
253 | 253 |
|
254 | 254 |
waitForHealthStatus(c, "failing_container", "starting", "unhealthy") |
255 | 255 |
|
256 |
- out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy") |
|
256 |
+ out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy").Combined() |
|
257 | 257 |
containerOut = strings.TrimSpace(out) |
258 | 258 |
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out)) |
259 | 259 |
|
... | ... |
@@ -263,7 +263,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) { |
263 | 263 |
|
264 | 264 |
waitForHealthStatus(c, "passing_container", "starting", "healthy") |
265 | 265 |
|
266 |
- out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy") |
|
266 |
+ out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy").Combined() |
|
267 | 267 |
containerOut = strings.TrimSpace(out) |
268 | 268 |
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out)) |
269 | 269 |
} |
... | ... |
@@ -6,6 +6,7 @@ import ( |
6 | 6 |
"time" |
7 | 7 |
|
8 | 8 |
"github.com/docker/docker/integration-cli/checker" |
9 |
+ "github.com/docker/docker/integration-cli/cli" |
|
9 | 10 |
"github.com/docker/docker/integration-cli/cli/build" |
10 | 11 |
"github.com/docker/docker/pkg/stringid" |
11 | 12 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
... | ... |
@@ -62,24 +63,22 @@ func (s *DockerSuite) TestRmiTag(c *check.C) { |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) { |
65 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'") |
|
66 |
- |
|
65 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'").Combined() |
|
67 | 66 |
containerID := strings.TrimSpace(out) |
68 | 67 |
|
69 | 68 |
// Wait for it to exit as cannot commit a running container on Windows, and |
70 | 69 |
// it will take a few seconds to exit |
71 | 70 |
if testEnv.DaemonPlatform() == "windows" { |
72 |
- err := waitExited(containerID, 60*time.Second) |
|
73 |
- c.Assert(err, check.IsNil) |
|
71 |
+ cli.WaitExited(c, containerID, 60*time.Second) |
|
74 | 72 |
} |
75 | 73 |
|
76 |
- dockerCmd(c, "commit", containerID, "busybox-one") |
|
74 |
+ cli.DockerCmd(c, "commit", containerID, "busybox-one") |
|
77 | 75 |
|
78 |
- imagesBefore, _ := dockerCmd(c, "images", "-a") |
|
79 |
- dockerCmd(c, "tag", "busybox-one", "busybox-one:tag1") |
|
80 |
- dockerCmd(c, "tag", "busybox-one", "busybox-one:tag2") |
|
76 |
+ imagesBefore := cli.DockerCmd(c, "images", "-a").Combined() |
|
77 |
+ cli.DockerCmd(c, "tag", "busybox-one", "busybox-one:tag1") |
|
78 |
+ cli.DockerCmd(c, "tag", "busybox-one", "busybox-one:tag2") |
|
81 | 79 |
|
82 |
- imagesAfter, _ := dockerCmd(c, "images", "-a") |
|
80 |
+ imagesAfter := cli.DockerCmd(c, "images", "-a").Combined() |
|
83 | 81 |
// tag busybox to create 2 more images with same imageID |
84 | 82 |
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("docker images shows: %q\n", imagesAfter)) |
85 | 83 |
|
... | ... |
@@ -87,59 +86,55 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) { |
87 | 87 |
|
88 | 88 |
// run a container with the image |
89 | 89 |
out, _ = runSleepingContainerInImage(c, "busybox-one") |
90 |
- |
|
91 | 90 |
containerID = strings.TrimSpace(out) |
92 | 91 |
|
93 | 92 |
// first checkout without force it fails |
94 |
- out, _, err := dockerCmdWithError("rmi", imgID) |
|
95 |
- expected := fmt.Sprintf("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s", stringid.TruncateID(imgID), stringid.TruncateID(containerID)) |
|
96 | 93 |
// rmi tagged in multiple repos should have failed without force |
97 |
- c.Assert(err, checker.NotNil) |
|
98 |
- c.Assert(out, checker.Contains, expected) |
|
94 |
+ cli.Docker(cli.Args("rmi", imgID)).Assert(c, icmd.Expected{ |
|
95 |
+ ExitCode: 1, |
|
96 |
+ Err: fmt.Sprintf("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s", stringid.TruncateID(imgID), stringid.TruncateID(containerID)), |
|
97 |
+ }) |
|
99 | 98 |
|
100 |
- dockerCmd(c, "stop", containerID) |
|
101 |
- dockerCmd(c, "rmi", "-f", imgID) |
|
99 |
+ cli.DockerCmd(c, "stop", containerID) |
|
100 |
+ cli.DockerCmd(c, "rmi", "-f", imgID) |
|
102 | 101 |
|
103 |
- imagesAfter, _ = dockerCmd(c, "images", "-a") |
|
102 |
+ imagesAfter = cli.DockerCmd(c, "images", "-a").Combined() |
|
104 | 103 |
// rmi -f failed, image still exists |
105 | 104 |
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12], check.Commentf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter)) |
106 | 105 |
} |
107 | 106 |
|
108 | 107 |
func (s *DockerSuite) TestRmiImgIDForce(c *check.C) { |
109 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'") |
|
110 |
- |
|
108 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'").Combined() |
|
111 | 109 |
containerID := strings.TrimSpace(out) |
112 | 110 |
|
113 | 111 |
// Wait for it to exit as cannot commit a running container on Windows, and |
114 | 112 |
// it will take a few seconds to exit |
115 | 113 |
if testEnv.DaemonPlatform() == "windows" { |
116 |
- err := waitExited(containerID, 60*time.Second) |
|
117 |
- c.Assert(err, check.IsNil) |
|
114 |
+ cli.WaitExited(c, containerID, 60*time.Second) |
|
118 | 115 |
} |
119 | 116 |
|
120 |
- dockerCmd(c, "commit", containerID, "busybox-test") |
|
117 |
+ cli.DockerCmd(c, "commit", containerID, "busybox-test") |
|
121 | 118 |
|
122 |
- imagesBefore, _ := dockerCmd(c, "images", "-a") |
|
123 |
- dockerCmd(c, "tag", "busybox-test", "utest:tag1") |
|
124 |
- dockerCmd(c, "tag", "busybox-test", "utest:tag2") |
|
125 |
- dockerCmd(c, "tag", "busybox-test", "utest/docker:tag3") |
|
126 |
- dockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4") |
|
119 |
+ imagesBefore := cli.DockerCmd(c, "images", "-a").Combined() |
|
120 |
+ cli.DockerCmd(c, "tag", "busybox-test", "utest:tag1") |
|
121 |
+ cli.DockerCmd(c, "tag", "busybox-test", "utest:tag2") |
|
122 |
+ cli.DockerCmd(c, "tag", "busybox-test", "utest/docker:tag3") |
|
123 |
+ cli.DockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4") |
|
127 | 124 |
{ |
128 |
- imagesAfter, _ := dockerCmd(c, "images", "-a") |
|
125 |
+ imagesAfter := cli.DockerCmd(c, "images", "-a").Combined() |
|
129 | 126 |
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+4, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter)) |
130 | 127 |
} |
131 | 128 |
imgID := inspectField(c, "busybox-test", "Id") |
132 | 129 |
|
133 | 130 |
// first checkout without force it fails |
134 |
- out, _, err := dockerCmdWithError("rmi", imgID) |
|
135 |
- // rmi tagged in multiple repos should have failed without force |
|
136 |
- c.Assert(err, checker.NotNil) |
|
137 |
- // rmi tagged in multiple repos should have failed without force |
|
138 |
- c.Assert(out, checker.Contains, "(must be forced) - image is referenced in multiple repositories", check.Commentf("out: %s; err: %v;", out, err)) |
|
131 |
+ cli.Docker(cli.Args("rmi", imgID)).Assert(c, icmd.Expected{ |
|
132 |
+ ExitCode: 1, |
|
133 |
+ Err: "(must be forced) - image is referenced in multiple repositories", |
|
134 |
+ }) |
|
139 | 135 |
|
140 |
- dockerCmd(c, "rmi", "-f", imgID) |
|
136 |
+ cli.DockerCmd(c, "rmi", "-f", imgID) |
|
141 | 137 |
{ |
142 |
- imagesAfter, _ := dockerCmd(c, "images", "-a") |
|
138 |
+ imagesAfter := cli.DockerCmd(c, "images", "-a").Combined() |
|
143 | 139 |
// rmi failed, image still exists |
144 | 140 |
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12]) |
145 | 141 |
} |
... | ... |
@@ -4260,10 +4260,9 @@ func (s *DockerSuite) TestRunCredentialSpecWellFormed(c *check.C) { |
4260 | 4260 |
func (s *DockerSuite) TestRunServicingContainer(c *check.C) { |
4261 | 4261 |
testRequires(c, DaemonIsWindows, SameHostDaemon) |
4262 | 4262 |
|
4263 |
- out, _ := dockerCmd(c, "run", "-d", testEnv.MinimalBaseImage(), "cmd", "/c", "mkdir c:\\programdata\\Microsoft\\Windows\\ContainerUpdates\\000_000_d99f45d0-ffc8-4af7-bd9c-ea6a62e035c9_200 && sc control cexecsvc 255") |
|
4263 |
+ out := cli.DockerCmd(c, "run", "-d", testEnv.MinimalBaseImage(), "cmd", "/c", "mkdir c:\\programdata\\Microsoft\\Windows\\ContainerUpdates\\000_000_d99f45d0-ffc8-4af7-bd9c-ea6a62e035c9_200 && sc control cexecsvc 255").Combined() |
|
4264 | 4264 |
containerID := strings.TrimSpace(out) |
4265 |
- err := waitExited(containerID, 60*time.Second) |
|
4266 |
- c.Assert(err, checker.IsNil) |
|
4265 |
+ cli.WaitExited(c, containerID, 60*time.Second) |
|
4267 | 4266 |
|
4268 | 4267 |
result := icmd.RunCommand("powershell", "echo", `(Get-WinEvent -ProviderName "Microsoft-Windows-Hyper-V-Compute" -FilterXPath 'Event[System[EventID=2010]]' -MaxEvents 1).Message`) |
4269 | 4268 |
result.Assert(c, icmd.Success) |
... | ... |
@@ -173,17 +173,15 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) { |
173 | 173 |
// Test case for #23716 |
174 | 174 |
func (s *DockerSuite) TestStartAttachWithRename(c *check.C) { |
175 | 175 |
testRequires(c, DaemonIsLinux) |
176 |
- dockerCmd(c, "create", "-t", "--name", "before", "busybox") |
|
176 |
+ cli.DockerCmd(c, "create", "-t", "--name", "before", "busybox") |
|
177 | 177 |
go func() { |
178 |
- c.Assert(waitRun("before"), checker.IsNil) |
|
179 |
- dockerCmd(c, "rename", "before", "after") |
|
180 |
- dockerCmd(c, "stop", "--time=2", "after") |
|
178 |
+ cli.WaitRun(c, "before") |
|
179 |
+ cli.DockerCmd(c, "rename", "before", "after") |
|
180 |
+ cli.DockerCmd(c, "stop", "--time=2", "after") |
|
181 | 181 |
}() |
182 | 182 |
// FIXME(vdemeester) the intent is not clear and potentially racey |
183 |
- result := icmd.RunCommand(dockerBinary, "start", "-a", "before") |
|
184 |
- result.Assert(c, icmd.Expected{ |
|
183 |
+ result := cli.Docker(cli.Args("start", "-a", "before")).Assert(c, icmd.Expected{ |
|
185 | 184 |
ExitCode: 137, |
186 |
- Error: "exit status 137", |
|
187 | 185 |
}) |
188 | 186 |
c.Assert(result.Stderr(), checker.Not(checker.Contains), "No such container") |
189 | 187 |
} |
... | ... |
@@ -8,6 +8,7 @@ import ( |
8 | 8 |
"time" |
9 | 9 |
|
10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
11 |
+ "github.com/docker/docker/integration-cli/cli" |
|
11 | 12 |
"github.com/go-check/check" |
12 | 13 |
) |
13 | 14 |
|
... | ... |
@@ -162,17 +163,17 @@ func (s *DockerSuite) TestStatsFormatAll(c *check.C) { |
162 | 162 |
// Windows does not support stats |
163 | 163 |
testRequires(c, DaemonIsLinux) |
164 | 164 |
|
165 |
- dockerCmd(c, "run", "-d", "--name=RunningOne", "busybox", "top") |
|
166 |
- c.Assert(waitRun("RunningOne"), check.IsNil) |
|
167 |
- dockerCmd(c, "run", "-d", "--name=ExitedOne", "busybox", "top") |
|
168 |
- dockerCmd(c, "stop", "ExitedOne") |
|
169 |
- c.Assert(waitExited("ExitedOne", 5*time.Second), check.IsNil) |
|
165 |
+ cli.DockerCmd(c, "run", "-d", "--name=RunningOne", "busybox", "top") |
|
166 |
+ cli.WaitRun(c, "RunningOne") |
|
167 |
+ cli.DockerCmd(c, "run", "-d", "--name=ExitedOne", "busybox", "top") |
|
168 |
+ cli.DockerCmd(c, "stop", "ExitedOne") |
|
169 |
+ cli.WaitExited(c, "ExitedOne", 5*time.Second) |
|
170 | 170 |
|
171 |
- out, _ := dockerCmd(c, "stats", "--no-stream", "--format", "{{.Name}}") |
|
171 |
+ out := cli.DockerCmd(c, "stats", "--no-stream", "--format", "{{.Name}}").Combined() |
|
172 | 172 |
c.Assert(out, checker.Contains, "RunningOne") |
173 | 173 |
c.Assert(out, checker.Not(checker.Contains), "ExitedOne") |
174 | 174 |
|
175 |
- out, _ = dockerCmd(c, "stats", "--all", "--no-stream", "--format", "{{.Name}}") |
|
175 |
+ out = cli.DockerCmd(c, "stats", "--all", "--no-stream", "--format", "{{.Name}}").Combined() |
|
176 | 176 |
c.Assert(out, checker.Contains, "RunningOne") |
177 | 177 |
c.Assert(out, checker.Contains, "ExitedOne") |
178 | 178 |
} |
... | ... |
@@ -5,11 +5,13 @@ import ( |
5 | 5 |
"time" |
6 | 6 |
|
7 | 7 |
"github.com/docker/docker/integration-cli/checker" |
8 |
+ "github.com/docker/docker/integration-cli/cli" |
|
9 |
+ icmd "github.com/docker/docker/pkg/testutil/cmd" |
|
8 | 10 |
"github.com/go-check/check" |
9 | 11 |
) |
10 | 12 |
|
11 | 13 |
func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) { |
12 |
- out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 1 && false") |
|
14 |
+ out := cli.DockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 1 && false").Combined() |
|
13 | 15 |
timeout := 60 * time.Second |
14 | 16 |
if testEnv.DaemonPlatform() == "windows" { |
15 | 17 |
timeout = 180 * time.Second |
... | ... |
@@ -18,10 +20,9 @@ func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) { |
18 | 18 |
id := strings.TrimSpace(string(out)) |
19 | 19 |
|
20 | 20 |
// update restart policy to on-failure:5 |
21 |
- dockerCmd(c, "update", "--restart=on-failure:5", id) |
|
21 |
+ cli.DockerCmd(c, "update", "--restart=on-failure:5", id) |
|
22 | 22 |
|
23 |
- err := waitExited(id, timeout) |
|
24 |
- c.Assert(err, checker.IsNil) |
|
23 |
+ cli.WaitExited(c, id, timeout) |
|
25 | 24 |
|
26 | 25 |
count := inspectField(c, id, "RestartCount") |
27 | 26 |
c.Assert(count, checker.Equals, "5") |
... | ... |
@@ -35,7 +36,8 @@ func (s *DockerSuite) TestUpdateRestartWithAutoRemoveFlag(c *check.C) { |
35 | 35 |
id := strings.TrimSpace(out) |
36 | 36 |
|
37 | 37 |
// update restart policy for an AutoRemove container |
38 |
- out, _, err := dockerCmdWithError("update", "--restart=always", id) |
|
39 |
- c.Assert(err, checker.NotNil) |
|
40 |
- c.Assert(out, checker.Contains, "Restart policy cannot be updated because AutoRemove is enabled for the container") |
|
38 |
+ cli.Docker(cli.Args("update", "--restart=always", id)).Assert(c, icmd.Expected{ |
|
39 |
+ ExitCode: 1, |
|
40 |
+ Err: "Restart policy cannot be updated because AutoRemove is enabled for the container", |
|
41 |
+ }) |
|
41 | 42 |
} |
... | ... |
@@ -458,38 +458,21 @@ func createTmpFile(c *check.C, content string) string { |
458 | 458 |
return filename |
459 | 459 |
} |
460 | 460 |
|
461 |
-func waitForContainer(contID string, args ...string) error { |
|
462 |
- args = append([]string{dockerBinary, "run", "--name", contID}, args...) |
|
463 |
- result := icmd.RunCmd(icmd.Cmd{Command: args}) |
|
464 |
- if result.Error != nil { |
|
465 |
- return result.Error |
|
466 |
- } |
|
467 |
- return waitRun(contID) |
|
468 |
-} |
|
469 |
- |
|
470 |
-// waitRestart will wait for the specified container to restart once |
|
471 |
-func waitRestart(contID string, duration time.Duration) error { |
|
472 |
- return waitInspect(contID, "{{.RestartCount}}", "1", duration) |
|
473 |
-} |
|
474 |
- |
|
475 | 461 |
// waitRun will wait for the specified container to be running, maximum 5 seconds. |
462 |
+// Deprecated: use cli.WaitFor |
|
476 | 463 |
func waitRun(contID string) error { |
477 | 464 |
return waitInspect(contID, "{{.State.Running}}", "true", 5*time.Second) |
478 | 465 |
} |
479 | 466 |
|
480 |
-// waitExited will wait for the specified container to state exit, subject |
|
481 |
-// to a maximum time limit in seconds supplied by the caller |
|
482 |
-func waitExited(contID string, duration time.Duration) error { |
|
483 |
- return waitInspect(contID, "{{.State.Status}}", "exited", duration) |
|
484 |
-} |
|
485 |
- |
|
486 | 467 |
// waitInspect will wait for the specified container to have the specified string |
487 | 468 |
// in the inspect output. It will wait until the specified timeout (in seconds) |
488 | 469 |
// is reached. |
470 |
+// Deprecated: use cli.WaitFor |
|
489 | 471 |
func waitInspect(name, expr, expected string, timeout time.Duration) error { |
490 | 472 |
return waitInspectWithArgs(name, expr, expected, timeout) |
491 | 473 |
} |
492 | 474 |
|
475 |
+// Deprecated: use cli.WaitFor |
|
493 | 476 |
func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg ...string) error { |
494 | 477 |
return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout, arg...) |
495 | 478 |
} |