Add some required command operators to the `cli` package, and update
some tests to use this package, in order to remove a few functions
from `docker_utils_test.go`
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -2,12 +2,15 @@ package cli |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
+ "io" |
|
| 6 |
+ "strings" |
|
| 5 | 7 |
"sync" |
| 6 | 8 |
"time" |
| 7 | 9 |
|
| 8 | 10 |
"github.com/docker/docker/integration-cli/daemon" |
| 9 | 11 |
"github.com/docker/docker/integration-cli/environment" |
| 10 | 12 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 13 |
+ "github.com/pkg/errors" |
|
| 11 | 14 |
) |
| 12 | 15 |
|
| 13 | 16 |
var ( |
| ... | ... |
@@ -40,8 +43,8 @@ type testingT interface {
|
| 40 | 40 |
} |
| 41 | 41 |
|
| 42 | 42 |
// DockerCmd executes the specified docker command and expect a success |
| 43 |
-func DockerCmd(t testingT, command string, args ...string) *icmd.Result {
|
|
| 44 |
- return Docker(Cmd(command, args...)).Assert(t, icmd.Success) |
|
| 43 |
+func DockerCmd(t testingT, args ...string) *icmd.Result {
|
|
| 44 |
+ return Docker(Args(args...)).Assert(t, icmd.Success) |
|
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 | 47 |
// BuildCmd executes the specified docker build command and expect a success |
| ... | ... |
@@ -63,9 +66,32 @@ func Docker(cmd icmd.Cmd, cmdOperators ...CmdOperator) *icmd.Result {
|
| 63 | 63 |
} |
| 64 | 64 |
} |
| 65 | 65 |
appendDocker(&cmd) |
| 66 |
+ if err := validateArgs(cmd.Command...); err != nil {
|
|
| 67 |
+ return &icmd.Result{
|
|
| 68 |
+ Error: err, |
|
| 69 |
+ } |
|
| 70 |
+ } |
|
| 66 | 71 |
return icmd.RunCmd(cmd) |
| 67 | 72 |
} |
| 68 | 73 |
|
| 74 |
+// validateArgs is a checker to ensure tests are not running commands which are |
|
| 75 |
+// not supported on platforms. Specifically on Windows this is 'busybox top'. |
|
| 76 |
+func validateArgs(args ...string) error {
|
|
| 77 |
+ if testEnv.DaemonPlatform() != "windows" {
|
|
| 78 |
+ return nil |
|
| 79 |
+ } |
|
| 80 |
+ foundBusybox := -1 |
|
| 81 |
+ for key, value := range args {
|
|
| 82 |
+ if strings.ToLower(value) == "busybox" {
|
|
| 83 |
+ foundBusybox = key |
|
| 84 |
+ } |
|
| 85 |
+ if (foundBusybox != -1) && (key == foundBusybox+1) && (strings.ToLower(value) == "top") {
|
|
| 86 |
+ return errors.New("cannot use 'busybox top' in tests on Windows. Use runSleepingContainer()")
|
|
| 87 |
+ } |
|
| 88 |
+ } |
|
| 89 |
+ return nil |
|
| 90 |
+} |
|
| 91 |
+ |
|
| 69 | 92 |
// Build executes the specified docker build command |
| 70 | 93 |
func Build(name string) icmd.Cmd {
|
| 71 | 94 |
return icmd.Command("build", "-t", name)
|
| ... | ... |
@@ -91,9 +117,16 @@ func appendDocker(cmd *icmd.Cmd) {
|
| 91 | 91 |
cmd.Command = append([]string{testEnv.DockerBinary()}, cmd.Command...)
|
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 |
-// Cmd build an icmd.Cmd struct from the specified command and arguments |
|
| 95 |
-func Cmd(command string, args ...string) icmd.Cmd {
|
|
| 96 |
- return icmd.Command(command, args...) |
|
| 94 |
+// Args build an icmd.Cmd struct from the specified arguments |
|
| 95 |
+func Args(args ...string) icmd.Cmd {
|
|
| 96 |
+ switch len(args) {
|
|
| 97 |
+ case 0: |
|
| 98 |
+ return icmd.Cmd{}
|
|
| 99 |
+ case 1: |
|
| 100 |
+ return icmd.Command(args[0]) |
|
| 101 |
+ default: |
|
| 102 |
+ return icmd.Command(args[0], args[1:]...) |
|
| 103 |
+ } |
|
| 97 | 104 |
} |
| 98 | 105 |
|
| 99 | 106 |
// Daemon points to the specified daemon |
| ... | ... |
@@ -127,3 +160,19 @@ func WithFlags(flags ...string) func(*icmd.Cmd) func() {
|
| 127 | 127 |
return nil |
| 128 | 128 |
} |
| 129 | 129 |
} |
| 130 |
+ |
|
| 131 |
+// InDir sets the folder in which the command should be executed |
|
| 132 |
+func InDir(path string) func(*icmd.Cmd) func() {
|
|
| 133 |
+ return func(cmd *icmd.Cmd) func() {
|
|
| 134 |
+ cmd.Dir = path |
|
| 135 |
+ return nil |
|
| 136 |
+ } |
|
| 137 |
+} |
|
| 138 |
+ |
|
| 139 |
+// WithStdout sets the standard output writer of the command |
|
| 140 |
+func WithStdout(writer io.Writer) func(*icmd.Cmd) func() {
|
|
| 141 |
+ return func(cmd *icmd.Cmd) func() {
|
|
| 142 |
+ cmd.Stdout = writer |
|
| 143 |
+ return nil |
|
| 144 |
+ } |
|
| 145 |
+} |
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
|
| 12 | 12 |
"github.com/docker/docker/api" |
| 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/request" |
| 15 | 16 |
"github.com/docker/docker/pkg/testutil" |
| 16 | 17 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| ... | ... |
@@ -71,10 +72,7 @@ func (s *DockerSuite) TestAPIDockerAPIVersion(c *check.C) {
|
| 71 | 71 |
defer server.Close() |
| 72 | 72 |
|
| 73 | 73 |
// Test using the env var first |
| 74 |
- result := icmd.RunCmd(icmd.Cmd{
|
|
| 75 |
- Command: binaryWithArgs("-H="+server.URL[7:], "version"),
|
|
| 76 |
- Env: appendBaseEnv(false, "DOCKER_API_VERSION=xxx"), |
|
| 77 |
- }) |
|
| 74 |
+ result := cli.Docker(cli.Args("-H="+server.URL[7:], "version"), cli.WithEnvironmentVariables("DOCKER_API_VERSION=xxx"))
|
|
| 78 | 75 |
c.Assert(result, icmd.Matches, icmd.Expected{Out: "API version: xxx", ExitCode: 1})
|
| 79 | 76 |
c.Assert(svrVersion, check.Equals, "/vxxx/version", check.Commentf("%s", result.Compare(icmd.Success)))
|
| 80 | 77 |
} |
| ... | ... |
@@ -3565,37 +3565,21 @@ func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) {
|
| 3565 | 3565 |
}) |
| 3566 | 3566 |
defer ctx.Close() |
| 3567 | 3567 |
|
| 3568 |
- out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".") |
|
| 3569 |
- if err != nil {
|
|
| 3570 |
- c.Fatalf("Failed to build: %s\n%s", out, err)
|
|
| 3571 |
- } |
|
| 3572 |
- if !strings.Contains(out, "from Dockerfile") {
|
|
| 3573 |
- c.Fatalf("test1 should have used Dockerfile, output:%s", out)
|
|
| 3574 |
- } |
|
| 3568 |
+ cli.Docker(cli.Args("build", "-t", "test1", "."), cli.InDir(ctx.Dir)).Assert(c, icmd.Expected{
|
|
| 3569 |
+ Out: "from Dockerfile", |
|
| 3570 |
+ }) |
|
| 3575 | 3571 |
|
| 3576 |
- out, _, err = dockerCmdInDir(c, ctx.Dir, "build", "-f", filepath.Join("files", "Dockerfile"), "-t", "test2", ".")
|
|
| 3577 |
- if err != nil {
|
|
| 3578 |
- c.Fatal(err) |
|
| 3579 |
- } |
|
| 3580 |
- if !strings.Contains(out, "from files/Dockerfile") {
|
|
| 3581 |
- c.Fatalf("test2 should have used files/Dockerfile, output:%s", out)
|
|
| 3582 |
- } |
|
| 3572 |
+ cli.Docker(cli.Args("build", "-f", filepath.Join("files", "Dockerfile"), "-t", "test2", "."), cli.InDir(ctx.Dir)).Assert(c, icmd.Expected{
|
|
| 3573 |
+ Out: "from files/Dockerfile", |
|
| 3574 |
+ }) |
|
| 3583 | 3575 |
|
| 3584 |
- out, _, err = dockerCmdInDir(c, ctx.Dir, "build", fmt.Sprintf("--file=%s", filepath.Join("files", "dFile")), "-t", "test3", ".")
|
|
| 3585 |
- if err != nil {
|
|
| 3586 |
- c.Fatal(err) |
|
| 3587 |
- } |
|
| 3588 |
- if !strings.Contains(out, "from files/dFile") {
|
|
| 3589 |
- c.Fatalf("test3 should have used files/dFile, output:%s", out)
|
|
| 3590 |
- } |
|
| 3576 |
+ cli.Docker(cli.Args("build", fmt.Sprintf("--file=%s", filepath.Join("files", "dFile")), "-t", "test3", "."), cli.InDir(ctx.Dir)).Assert(c, icmd.Expected{
|
|
| 3577 |
+ Out: "from files/dFile", |
|
| 3578 |
+ }) |
|
| 3591 | 3579 |
|
| 3592 |
- out, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--file=dFile", "-t", "test4", ".") |
|
| 3593 |
- if err != nil {
|
|
| 3594 |
- c.Fatal(err) |
|
| 3595 |
- } |
|
| 3596 |
- if !strings.Contains(out, "from dFile") {
|
|
| 3597 |
- c.Fatalf("test4 should have used dFile, output:%s", out)
|
|
| 3598 |
- } |
|
| 3580 |
+ cli.Docker(cli.Args("build", "--file=dFile", "-t", "test4", "."), cli.InDir(ctx.Dir)).Assert(c, icmd.Expected{
|
|
| 3581 |
+ Out: "from dFile", |
|
| 3582 |
+ }) |
|
| 3599 | 3583 |
|
| 3600 | 3584 |
dirWithNoDockerfile, err := ioutil.TempDir(os.TempDir(), "test5") |
| 3601 | 3585 |
c.Assert(err, check.IsNil) |
| ... | ... |
@@ -3603,54 +3587,32 @@ func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) {
|
| 3603 | 3603 |
if _, err = os.Create(nonDockerfileFile); err != nil {
|
| 3604 | 3604 |
c.Fatal(err) |
| 3605 | 3605 |
} |
| 3606 |
- out, _, err = dockerCmdInDir(c, ctx.Dir, "build", fmt.Sprintf("--file=%s", nonDockerfileFile), "-t", "test5", ".")
|
|
| 3607 |
- |
|
| 3608 |
- if err == nil {
|
|
| 3609 |
- c.Fatalf("test5 was supposed to fail to find passwd")
|
|
| 3610 |
- } |
|
| 3611 |
- |
|
| 3612 |
- if expected := fmt.Sprintf("The Dockerfile (%s) must be within the build context (.)", nonDockerfileFile); !strings.Contains(out, expected) {
|
|
| 3613 |
- c.Fatalf("wrong error message:%v\nexpected to contain=%v", out, expected)
|
|
| 3614 |
- } |
|
| 3606 |
+ cli.Docker(cli.Args("build", fmt.Sprintf("--file=%s", nonDockerfileFile), "-t", "test5", "."), cli.InDir(ctx.Dir)).Assert(c, icmd.Expected{
|
|
| 3607 |
+ ExitCode: 1, |
|
| 3608 |
+ Err: fmt.Sprintf("The Dockerfile (%s) must be within the build context (.)", nonDockerfileFile),
|
|
| 3609 |
+ }) |
|
| 3615 | 3610 |
|
| 3616 |
- out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test6", "..")
|
|
| 3617 |
- if err != nil {
|
|
| 3618 |
- c.Fatalf("test6 failed: %s", err)
|
|
| 3619 |
- } |
|
| 3620 |
- if !strings.Contains(out, "from Dockerfile") {
|
|
| 3621 |
- c.Fatalf("test6 should have used root Dockerfile, output:%s", out)
|
|
| 3622 |
- } |
|
| 3611 |
+ cli.Docker(cli.Args("build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test6", ".."), cli.InDir(filepath.Join(ctx.Dir, "files"))).Assert(c, icmd.Expected{
|
|
| 3612 |
+ Out: "from Dockerfile", |
|
| 3613 |
+ }) |
|
| 3623 | 3614 |
|
| 3624 |
- out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join(ctx.Dir, "files", "Dockerfile"), "-t", "test7", "..") |
|
| 3625 |
- if err != nil {
|
|
| 3626 |
- c.Fatalf("test7 failed: %s", err)
|
|
| 3627 |
- } |
|
| 3628 |
- if !strings.Contains(out, "from files/Dockerfile") {
|
|
| 3629 |
- c.Fatalf("test7 should have used files Dockerfile, output:%s", out)
|
|
| 3630 |
- } |
|
| 3615 |
+ cli.Docker(cli.Args("build", "-f", filepath.Join(ctx.Dir, "files", "Dockerfile"), "-t", "test7", ".."), cli.InDir(filepath.Join(ctx.Dir, "files"))).Assert(c, icmd.Expected{
|
|
| 3616 |
+ Out: "from files/Dockerfile", |
|
| 3617 |
+ }) |
|
| 3631 | 3618 |
|
| 3632 |
- out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test8", ".")
|
|
| 3633 |
- if err == nil || !strings.Contains(out, "must be within the build context") {
|
|
| 3634 |
- c.Fatalf("test8 should have failed with Dockerfile out of context: %s", err)
|
|
| 3635 |
- } |
|
| 3619 |
+ cli.Docker(cli.Args("build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test8", "."), cli.InDir(filepath.Join(ctx.Dir, "files"))).Assert(c, icmd.Expected{
|
|
| 3620 |
+ ExitCode: 1, |
|
| 3621 |
+ Err: "must be within the build context", |
|
| 3622 |
+ }) |
|
| 3636 | 3623 |
|
| 3637 | 3624 |
tmpDir := os.TempDir() |
| 3638 |
- out, _, err = dockerCmdInDir(c, tmpDir, "build", "-t", "test9", ctx.Dir) |
|
| 3639 |
- if err != nil {
|
|
| 3640 |
- c.Fatalf("test9 - failed: %s", err)
|
|
| 3641 |
- } |
|
| 3642 |
- if !strings.Contains(out, "from Dockerfile") {
|
|
| 3643 |
- c.Fatalf("test9 should have used root Dockerfile, output:%s", out)
|
|
| 3644 |
- } |
|
| 3645 |
- |
|
| 3646 |
- out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", "dFile2", "-t", "test10", ".") |
|
| 3647 |
- if err != nil {
|
|
| 3648 |
- c.Fatalf("test10 should have worked: %s", err)
|
|
| 3649 |
- } |
|
| 3650 |
- if !strings.Contains(out, "from files/dFile2") {
|
|
| 3651 |
- c.Fatalf("test10 should have used files/dFile2, output:%s", out)
|
|
| 3652 |
- } |
|
| 3625 |
+ cli.Docker(cli.Args("build", "-t", "test9", ctx.Dir), cli.InDir(tmpDir)).Assert(c, icmd.Expected{
|
|
| 3626 |
+ Out: "from Dockerfile", |
|
| 3627 |
+ }) |
|
| 3653 | 3628 |
|
| 3629 |
+ cli.Docker(cli.Args("build", "-f", "dFile2", "-t", "test10", "."), cli.InDir(filepath.Join(ctx.Dir, "files"))).Assert(c, icmd.Expected{
|
|
| 3630 |
+ Out: "from files/dFile2", |
|
| 3631 |
+ }) |
|
| 3654 | 3632 |
} |
| 3655 | 3633 |
|
| 3656 | 3634 |
func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) {
|
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
"time" |
| 16 | 16 |
|
| 17 | 17 |
"github.com/docker/docker/integration-cli/checker" |
| 18 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 18 | 19 |
"github.com/docker/docker/pkg/testutil" |
| 19 | 20 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 20 | 21 |
"github.com/docker/go-units" |
| ... | ... |
@@ -29,12 +30,12 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
| 29 | 29 |
FROM hello-world:frozen |
| 30 | 30 |
RUN ["/hello"] |
| 31 | 31 |
`, map[string]string{})
|
| 32 |
- _, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".") |
|
| 33 |
- if err != nil {
|
|
| 34 |
- c.Fatal(err) |
|
| 35 |
- } |
|
| 32 |
+ cli.Docker( |
|
| 33 |
+ cli.Args("build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, "."),
|
|
| 34 |
+ cli.InDir(ctx.Dir), |
|
| 35 |
+ ).Assert(c, icmd.Success) |
|
| 36 | 36 |
|
| 37 |
- out, _ := dockerCmd(c, "ps", "-lq") |
|
| 37 |
+ out := cli.DockerCmd(c, "ps", "-lq").Combined() |
|
| 38 | 38 |
cID := strings.TrimSpace(out) |
| 39 | 39 |
|
| 40 | 40 |
type hostConfig struct {
|
| ... | ... |
@@ -50,7 +51,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
| 50 | 50 |
cfg := inspectFieldJSON(c, cID, "HostConfig") |
| 51 | 51 |
|
| 52 | 52 |
var c1 hostConfig |
| 53 |
- err = json.Unmarshal([]byte(cfg), &c1) |
|
| 53 |
+ err := json.Unmarshal([]byte(cfg), &c1) |
|
| 54 | 54 |
c.Assert(err, checker.IsNil, check.Commentf(cfg)) |
| 55 | 55 |
|
| 56 | 56 |
c.Assert(c1.Memory, checker.Equals, int64(64*1024*1024), check.Commentf("resource constraints not set properly for Memory"))
|
| ... | ... |
@@ -63,7 +64,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
| 63 | 63 |
c.Assert(c1.Ulimits[0].Hard, checker.Equals, int64(42), check.Commentf("resource constraints not set properly for Ulimits"))
|
| 64 | 64 |
|
| 65 | 65 |
// Make sure constraints aren't saved to image |
| 66 |
- dockerCmd(c, "run", "--name=test", name) |
|
| 66 |
+ cli.DockerCmd(c, "run", "--name=test", name) |
|
| 67 | 67 |
|
| 68 | 68 |
cfg = inspectFieldJSON(c, "test", "HostConfig") |
| 69 | 69 |
|
| ... | ... |
@@ -49,19 +49,19 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithRunningContainersPorts(c *check |
| 49 | 49 |
s.d.StartWithBusybox(c) |
| 50 | 50 |
|
| 51 | 51 |
cli.Docker( |
| 52 |
- cli.Cmd("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top"),
|
|
| 52 |
+ cli.Args("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top"),
|
|
| 53 | 53 |
cli.Daemon(s.d), |
| 54 | 54 |
).Assert(c, icmd.Success) |
| 55 | 55 |
|
| 56 | 56 |
cli.Docker( |
| 57 |
- cli.Cmd("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top"),
|
|
| 57 |
+ cli.Args("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top"),
|
|
| 58 | 58 |
cli.Daemon(s.d), |
| 59 | 59 |
).Assert(c, icmd.Success) |
| 60 | 60 |
|
| 61 | 61 |
testRun := func(m map[string]bool, prefix string) {
|
| 62 | 62 |
var format string |
| 63 | 63 |
for cont, shouldRun := range m {
|
| 64 |
- out := cli.Docker(cli.Cmd("ps"), cli.Daemon(s.d)).Assert(c, icmd.Success).Combined()
|
|
| 64 |
+ out := cli.Docker(cli.Args("ps"), cli.Daemon(s.d)).Assert(c, icmd.Success).Combined()
|
|
| 65 | 65 |
if shouldRun {
|
| 66 | 66 |
format = "%scontainer %q is not running" |
| 67 | 67 |
} else {
|
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"unicode" |
| 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/pkg/homedir" |
| 11 | 12 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 12 | 13 |
"github.com/go-check/check" |
| ... | ... |
@@ -149,29 +150,29 @@ func (s *DockerSuite) TestHelpExitCodesHelpOutput(c *check.C) {
|
| 149 | 149 |
// various good and bad cases are what we expect |
| 150 | 150 |
|
| 151 | 151 |
// docker : stdout=all, stderr=empty, rc=0 |
| 152 |
- out, _ := dockerCmd(c) |
|
| 152 |
+ out := cli.DockerCmd(c).Combined() |
|
| 153 | 153 |
// Be really pick |
| 154 | 154 |
c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker'\n"))
|
| 155 | 155 |
|
| 156 | 156 |
// docker help: stdout=all, stderr=empty, rc=0 |
| 157 |
- out, _ = dockerCmd(c, "help") |
|
| 157 |
+ out = cli.DockerCmd(c, "help").Combined() |
|
| 158 | 158 |
// Be really pick |
| 159 | 159 |
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 | 160 |
|
| 161 | 161 |
// docker --help: stdout=all, stderr=empty, rc=0 |
| 162 |
- out, _ = dockerCmd(c, "--help") |
|
| 162 |
+ out = cli.DockerCmd(c, "--help").Combined() |
|
| 163 | 163 |
// Be really pick |
| 164 | 164 |
c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker --help'\n"))
|
| 165 | 165 |
|
| 166 | 166 |
// docker inspect busybox: stdout=all, stderr=empty, rc=0 |
| 167 | 167 |
// Just making sure stderr is empty on valid cmd |
| 168 |
- out, _ = dockerCmd(c, "inspect", "busybox") |
|
| 168 |
+ out = cli.DockerCmd(c, "inspect", "busybox").Combined() |
|
| 169 | 169 |
// Be really pick |
| 170 | 170 |
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"))
|
| 171 | 171 |
|
| 172 | 172 |
// docker rm: stdout=empty, stderr=all, rc!=0 |
| 173 | 173 |
// testing the min arg error msg |
| 174 |
- icmd.RunCommand(dockerBinary, "rm").Assert(c, icmd.Expected{
|
|
| 174 |
+ cli.Docker(cli.Args("rm")).Assert(c, icmd.Expected{
|
|
| 175 | 175 |
ExitCode: 1, |
| 176 | 176 |
Error: "exit status 1", |
| 177 | 177 |
Out: "", |
| ... | ... |
@@ -182,8 +183,7 @@ func (s *DockerSuite) TestHelpExitCodesHelpOutput(c *check.C) {
|
| 182 | 182 |
|
| 183 | 183 |
// docker rm NoSuchContainer: stdout=empty, stderr=all, rc=0 |
| 184 | 184 |
// testing to make sure no blank line on error |
| 185 |
- result := icmd.RunCommand(dockerBinary, "rm", "NoSuchContainer") |
|
| 186 |
- result.Assert(c, icmd.Expected{
|
|
| 185 |
+ result := cli.Docker(cli.Args("rm", "NoSuchContainer")).Assert(c, icmd.Expected{
|
|
| 187 | 186 |
ExitCode: 1, |
| 188 | 187 |
Error: "exit status 1", |
| 189 | 188 |
Out: "", |
| ... | ... |
@@ -193,7 +193,7 @@ func (s *DockerSuite) TestHelpExitCodesHelpOutput(c *check.C) {
|
| 193 | 193 |
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"))
|
| 194 | 194 |
|
| 195 | 195 |
// docker BadCmd: stdout=empty, stderr=all, rc=0 |
| 196 |
- icmd.RunCommand(dockerBinary, "BadCmd").Assert(c, icmd.Expected{
|
|
| 196 |
+ cli.Docker(cli.Args("BadCmd")).Assert(c, icmd.Expected{
|
|
| 197 | 197 |
ExitCode: 1, |
| 198 | 198 |
Error: "exit status 1", |
| 199 | 199 |
Out: "", |
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"strings" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/docker/docker/integration-cli/checker" |
| 13 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 13 | 14 |
"github.com/docker/docker/pkg/testutil" |
| 14 | 15 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 15 | 16 |
"github.com/go-check/check" |
| ... | ... |
@@ -126,22 +127,17 @@ func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
|
| 126 | 126 |
|
| 127 | 127 |
func (s *DockerSuite) TestImportWithQuotedChanges(c *check.C) {
|
| 128 | 128 |
testRequires(c, DaemonIsLinux) |
| 129 |
- dockerCmd(c, "run", "--name", "test-import", "busybox", "true") |
|
| 129 |
+ cli.DockerCmd(c, "run", "--name", "test-import", "busybox", "true") |
|
| 130 | 130 |
|
| 131 | 131 |
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
| 132 | 132 |
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
| 133 | 133 |
defer os.Remove(temporaryFile.Name()) |
| 134 | 134 |
|
| 135 |
- result := icmd.RunCmd(icmd.Cmd{
|
|
| 136 |
- Command: binaryWithArgs("export", "test-import"),
|
|
| 137 |
- Stdout: bufio.NewWriter(temporaryFile), |
|
| 138 |
- }) |
|
| 139 |
- c.Assert(result, icmd.Matches, icmd.Success) |
|
| 135 |
+ cli.Docker(cli.Args("export", "test-import"), cli.WithStdout(bufio.NewWriter(temporaryFile))).Assert(c, icmd.Success)
|
|
| 140 | 136 |
|
| 141 |
- result = dockerCmdWithResult("import", "-c", `ENTRYPOINT ["/bin/sh", "-c"]`, temporaryFile.Name())
|
|
| 142 |
- c.Assert(result, icmd.Matches, icmd.Success) |
|
| 137 |
+ result := cli.DockerCmd(c, "import", "-c", `ENTRYPOINT ["/bin/sh", "-c"]`, temporaryFile.Name()) |
|
| 143 | 138 |
image := strings.TrimSpace(result.Stdout()) |
| 144 | 139 |
|
| 145 |
- result = dockerCmdWithResult("run", "--rm", image, "true")
|
|
| 140 |
+ result = cli.DockerCmd(c, "run", "--rm", image, "true") |
|
| 146 | 141 |
c.Assert(result, icmd.Matches, icmd.Expected{Out: icmd.None})
|
| 147 | 142 |
} |
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"time" |
| 10 | 10 |
|
| 11 | 11 |
"github.com/docker/docker/integration-cli/checker" |
| 12 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 12 | 13 |
"github.com/docker/docker/pkg/jsonlog" |
| 13 | 14 |
"github.com/docker/docker/pkg/testutil" |
| 14 | 15 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| ... | ... |
@@ -65,18 +66,13 @@ func (s *DockerSuite) TestLogsTimestamps(c *check.C) {
|
| 65 | 65 |
|
| 66 | 66 |
func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) {
|
| 67 | 67 |
msg := "stderr_log" |
| 68 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
|
| 69 |
- |
|
| 68 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)).Combined()
|
|
| 70 | 69 |
id := strings.TrimSpace(out) |
| 71 |
- dockerCmd(c, "wait", id) |
|
| 72 |
- |
|
| 73 |
- stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", id) |
|
| 74 |
- |
|
| 75 |
- c.Assert(stdout, checker.Equals, "") |
|
| 76 |
- |
|
| 77 |
- stderr = strings.TrimSpace(stderr) |
|
| 78 |
- |
|
| 79 |
- c.Assert(stderr, checker.Equals, msg) |
|
| 70 |
+ cli.DockerCmd(c, "wait", id) |
|
| 71 |
+ cli.DockerCmd(c, "logs", id).Assert(c, icmd.Expected{
|
|
| 72 |
+ Out: "", |
|
| 73 |
+ Err: msg, |
|
| 74 |
+ }) |
|
| 80 | 75 |
} |
| 81 | 76 |
|
| 82 | 77 |
func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
| ... | ... |
@@ -84,46 +80,44 @@ func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
| 84 | 84 |
// a bunch of ANSI escape sequences before the "stderr_log" message. |
| 85 | 85 |
testRequires(c, DaemonIsLinux) |
| 86 | 86 |
msg := "stderr_log" |
| 87 |
- out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
|
| 88 |
- |
|
| 87 |
+ out := cli.DockerCmd(c, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)).Combined()
|
|
| 89 | 88 |
id := strings.TrimSpace(out) |
| 90 |
- dockerCmd(c, "wait", id) |
|
| 89 |
+ cli.DockerCmd(c, "wait", id) |
|
| 91 | 90 |
|
| 92 |
- stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", id) |
|
| 93 |
- c.Assert(stderr, checker.Equals, "") |
|
| 94 |
- |
|
| 95 |
- stdout = strings.TrimSpace(stdout) |
|
| 96 |
- c.Assert(stdout, checker.Equals, msg) |
|
| 91 |
+ cli.DockerCmd(c, "logs", id).Assert(c, icmd.Expected{
|
|
| 92 |
+ Out: msg, |
|
| 93 |
+ Err: "", |
|
| 94 |
+ }) |
|
| 97 | 95 |
} |
| 98 | 96 |
|
| 99 | 97 |
func (s *DockerSuite) TestLogsTail(c *check.C) {
|
| 100 | 98 |
testLen := 100 |
| 101 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen))
|
|
| 99 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)).Combined()
|
|
| 102 | 100 |
|
| 103 | 101 |
id := strings.TrimSpace(out) |
| 104 |
- dockerCmd(c, "wait", id) |
|
| 102 |
+ cli.DockerCmd(c, "wait", id) |
|
| 105 | 103 |
|
| 106 |
- out, _ = dockerCmd(c, "logs", "--tail", "0", id) |
|
| 104 |
+ out = cli.DockerCmd(c, "logs", "--tail", "0", id).Combined() |
|
| 107 | 105 |
lines := strings.Split(out, "\n") |
| 108 | 106 |
c.Assert(lines, checker.HasLen, 1) |
| 109 | 107 |
|
| 110 |
- out, _ = dockerCmd(c, "logs", "--tail", "5", id) |
|
| 108 |
+ out = cli.DockerCmd(c, "logs", "--tail", "5", id).Combined() |
|
| 111 | 109 |
lines = strings.Split(out, "\n") |
| 112 | 110 |
c.Assert(lines, checker.HasLen, 6) |
| 113 | 111 |
|
| 114 |
- out, _ = dockerCmd(c, "logs", "--tail", "99", id) |
|
| 112 |
+ out = cli.DockerCmd(c, "logs", "--tail", "99", id).Combined() |
|
| 115 | 113 |
lines = strings.Split(out, "\n") |
| 116 | 114 |
c.Assert(lines, checker.HasLen, 100) |
| 117 | 115 |
|
| 118 |
- out, _ = dockerCmd(c, "logs", "--tail", "all", id) |
|
| 116 |
+ out = cli.DockerCmd(c, "logs", "--tail", "all", id).Combined() |
|
| 119 | 117 |
lines = strings.Split(out, "\n") |
| 120 | 118 |
c.Assert(lines, checker.HasLen, testLen+1) |
| 121 | 119 |
|
| 122 |
- out, _ = dockerCmd(c, "logs", "--tail", "-1", id) |
|
| 120 |
+ out = cli.DockerCmd(c, "logs", "--tail", "-1", id).Combined() |
|
| 123 | 121 |
lines = strings.Split(out, "\n") |
| 124 | 122 |
c.Assert(lines, checker.HasLen, testLen+1) |
| 125 | 123 |
|
| 126 |
- out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", id) |
|
| 124 |
+ out = cli.DockerCmd(c, "logs", "--tail", "random", id).Combined() |
|
| 127 | 125 |
lines = strings.Split(out, "\n") |
| 128 | 126 |
c.Assert(lines, checker.HasLen, testLen+1) |
| 129 | 127 |
} |
| ... | ... |
@@ -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/cli/build" |
| 15 | 16 |
"github.com/docker/docker/pkg/stringid" |
| 16 | 17 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| ... | ... |
@@ -185,26 +186,26 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
| 185 | 185 |
|
| 186 | 186 |
func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
| 187 | 187 |
// start exited container |
| 188 |
- out, _ := dockerCmd(c, "run", "-d", "busybox") |
|
| 188 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox").Combined() |
|
| 189 | 189 |
firstID := strings.TrimSpace(out) |
| 190 | 190 |
|
| 191 | 191 |
// make sure the exited container is not running |
| 192 |
- dockerCmd(c, "wait", firstID) |
|
| 192 |
+ cli.DockerCmd(c, "wait", firstID) |
|
| 193 | 193 |
|
| 194 | 194 |
// start running container |
| 195 |
- out, _ = dockerCmd(c, "run", "-itd", "busybox") |
|
| 195 |
+ out = cli.DockerCmd(c, "run", "-itd", "busybox").Combined() |
|
| 196 | 196 |
secondID := strings.TrimSpace(out) |
| 197 | 197 |
|
| 198 | 198 |
// filter containers by exited |
| 199 |
- out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=exited") |
|
| 199 |
+ out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=exited").Combined() |
|
| 200 | 200 |
containerOut := strings.TrimSpace(out) |
| 201 | 201 |
c.Assert(containerOut, checker.Equals, firstID) |
| 202 | 202 |
|
| 203 |
- out, _ = dockerCmd(c, "ps", "-a", "--no-trunc", "-q", "--filter=status=running") |
|
| 203 |
+ out = cli.DockerCmd(c, "ps", "-a", "--no-trunc", "-q", "--filter=status=running").Combined() |
|
| 204 | 204 |
containerOut = strings.TrimSpace(out) |
| 205 | 205 |
c.Assert(containerOut, checker.Equals, secondID) |
| 206 | 206 |
|
| 207 |
- result := dockerCmdWithTimeout(time.Second*60, "ps", "-a", "-q", "--filter=status=rubbish") |
|
| 207 |
+ result := cli.Docker(cli.Args("ps", "-a", "-q", "--filter=status=rubbish"), cli.WithTimeout(time.Second*60))
|
|
| 208 | 208 |
c.Assert(result, icmd.Matches, icmd.Expected{
|
| 209 | 209 |
ExitCode: 1, |
| 210 | 210 |
Err: "Unrecognised filter value for status", |
| ... | ... |
@@ -213,13 +214,13 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
| 213 | 213 |
// Windows doesn't support pausing of containers |
| 214 | 214 |
if testEnv.DaemonPlatform() != "windows" {
|
| 215 | 215 |
// pause running container |
| 216 |
- out, _ = dockerCmd(c, "run", "-itd", "busybox") |
|
| 216 |
+ out = cli.DockerCmd(c, "run", "-itd", "busybox").Combined() |
|
| 217 | 217 |
pausedID := strings.TrimSpace(out) |
| 218 |
- dockerCmd(c, "pause", pausedID) |
|
| 218 |
+ cli.DockerCmd(c, "pause", pausedID) |
|
| 219 | 219 |
// make sure the container is unpaused to let the daemon stop it properly |
| 220 |
- defer func() { dockerCmd(c, "unpause", pausedID) }()
|
|
| 220 |
+ defer func() { cli.DockerCmd(c, "unpause", pausedID) }()
|
|
| 221 | 221 |
|
| 222 |
- out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused") |
|
| 222 |
+ out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused").Combined() |
|
| 223 | 223 |
containerOut = strings.TrimSpace(out) |
| 224 | 224 |
c.Assert(containerOut, checker.Equals, pausedID) |
| 225 | 225 |
} |
| ... | ... |
@@ -22,6 +22,7 @@ import ( |
| 22 | 22 |
"time" |
| 23 | 23 |
|
| 24 | 24 |
"github.com/docker/docker/integration-cli/checker" |
| 25 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 25 | 26 |
"github.com/docker/docker/integration-cli/cli/build" |
| 26 | 27 |
"github.com/docker/docker/pkg/mount" |
| 27 | 28 |
"github.com/docker/docker/pkg/stringid" |
| ... | ... |
@@ -1285,19 +1286,19 @@ func (s *DockerSuite) TestRunDNSOptions(c *check.C) {
|
| 1285 | 1285 |
// Not applicable on Windows as Windows does not support --dns*, or |
| 1286 | 1286 |
// the Unix-specific functionality of resolv.conf. |
| 1287 | 1287 |
testRequires(c, DaemonIsLinux) |
| 1288 |
- out, stderr, _ := dockerCmdWithStdoutStderr(c, "run", "--dns=127.0.0.1", "--dns-search=mydomain", "--dns-opt=ndots:9", "busybox", "cat", "/etc/resolv.conf") |
|
| 1288 |
+ result := cli.DockerCmd(c, "run", "--dns=127.0.0.1", "--dns-search=mydomain", "--dns-opt=ndots:9", "busybox", "cat", "/etc/resolv.conf") |
|
| 1289 | 1289 |
|
| 1290 | 1290 |
// The client will get a warning on stderr when setting DNS to a localhost address; verify this: |
| 1291 |
- if !strings.Contains(stderr, "Localhost DNS setting") {
|
|
| 1292 |
- c.Fatalf("Expected warning on stderr about localhost resolver, but got %q", stderr)
|
|
| 1291 |
+ if !strings.Contains(result.Stderr(), "Localhost DNS setting") {
|
|
| 1292 |
+ c.Fatalf("Expected warning on stderr about localhost resolver, but got %q", result.Stderr())
|
|
| 1293 | 1293 |
} |
| 1294 | 1294 |
|
| 1295 |
- actual := strings.Replace(strings.Trim(out, "\r\n"), "\n", " ", -1) |
|
| 1295 |
+ actual := strings.Replace(strings.Trim(result.Stdout(), "\r\n"), "\n", " ", -1) |
|
| 1296 | 1296 |
if actual != "search mydomain nameserver 127.0.0.1 options ndots:9" {
|
| 1297 | 1297 |
c.Fatalf("expected 'search mydomain nameserver 127.0.0.1 options ndots:9', but says: %q", actual)
|
| 1298 | 1298 |
} |
| 1299 | 1299 |
|
| 1300 |
- out, _ = dockerCmd(c, "run", "--dns=1.1.1.1", "--dns-search=.", "--dns-opt=ndots:3", "busybox", "cat", "/etc/resolv.conf") |
|
| 1300 |
+ out := cli.DockerCmd(c, "run", "--dns=1.1.1.1", "--dns-search=.", "--dns-opt=ndots:3", "busybox", "cat", "/etc/resolv.conf").Combined() |
|
| 1301 | 1301 |
|
| 1302 | 1302 |
actual = strings.Replace(strings.Trim(strings.Trim(out, "\r\n"), " "), "\n", " ", -1) |
| 1303 | 1303 |
if actual != "nameserver 1.1.1.1 options ndots:3" {
|
| ... | ... |
@@ -1307,7 +1308,7 @@ func (s *DockerSuite) TestRunDNSOptions(c *check.C) {
|
| 1307 | 1307 |
|
| 1308 | 1308 |
func (s *DockerSuite) TestRunDNSRepeatOptions(c *check.C) {
|
| 1309 | 1309 |
testRequires(c, DaemonIsLinux) |
| 1310 |
- out, _, _ := dockerCmdWithStdoutStderr(c, "run", "--dns=1.1.1.1", "--dns=2.2.2.2", "--dns-search=mydomain", "--dns-search=mydomain2", "--dns-opt=ndots:9", "--dns-opt=timeout:3", "busybox", "cat", "/etc/resolv.conf") |
|
| 1310 |
+ out := cli.DockerCmd(c, "run", "--dns=1.1.1.1", "--dns=2.2.2.2", "--dns-search=mydomain", "--dns-search=mydomain2", "--dns-opt=ndots:9", "--dns-opt=timeout:3", "busybox", "cat", "/etc/resolv.conf").Stdout() |
|
| 1311 | 1311 |
|
| 1312 | 1312 |
actual := strings.Replace(strings.Trim(out, "\r\n"), "\n", " ", -1) |
| 1313 | 1313 |
if actual != "search mydomain mydomain2 nameserver 1.1.1.1 nameserver 2.2.2.2 options ndots:9 timeout:3" {
|
| ... | ... |
@@ -4093,26 +4094,30 @@ func (s *DockerSuite) TestRunDNSInHostMode(c *check.C) {
|
| 4093 | 4093 |
|
| 4094 | 4094 |
expectedOutput := "nameserver 127.0.0.1" |
| 4095 | 4095 |
expectedWarning := "Localhost DNS setting" |
| 4096 |
- out, stderr, _ := dockerCmdWithStdoutStderr(c, "run", "--dns=127.0.0.1", "--net=host", "busybox", "cat", "/etc/resolv.conf") |
|
| 4097 |
- c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
|
|
| 4098 |
- c.Assert(stderr, checker.Contains, expectedWarning, check.Commentf("Expected warning on stderr about localhost resolver, but got %q", stderr))
|
|
| 4096 |
+ cli.DockerCmd(c, "run", "--dns=127.0.0.1", "--net=host", "busybox", "cat", "/etc/resolv.conf").Assert(c, icmd.Expected{
|
|
| 4097 |
+ Out: expectedOutput, |
|
| 4098 |
+ Err: expectedWarning, |
|
| 4099 |
+ }) |
|
| 4099 | 4100 |
|
| 4100 | 4101 |
expectedOutput = "nameserver 1.2.3.4" |
| 4101 |
- out, _ = dockerCmd(c, "run", "--dns=1.2.3.4", "--net=host", "busybox", "cat", "/etc/resolv.conf") |
|
| 4102 |
- c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
|
|
| 4102 |
+ cli.DockerCmd(c, "run", "--dns=1.2.3.4", "--net=host", "busybox", "cat", "/etc/resolv.conf").Assert(c, icmd.Expected{
|
|
| 4103 |
+ Out: expectedOutput, |
|
| 4104 |
+ }) |
|
| 4103 | 4105 |
|
| 4104 | 4106 |
expectedOutput = "search example.com" |
| 4105 |
- out, _ = dockerCmd(c, "run", "--dns-search=example.com", "--net=host", "busybox", "cat", "/etc/resolv.conf") |
|
| 4106 |
- c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
|
|
| 4107 |
+ cli.DockerCmd(c, "run", "--dns-search=example.com", "--net=host", "busybox", "cat", "/etc/resolv.conf").Assert(c, icmd.Expected{
|
|
| 4108 |
+ Out: expectedOutput, |
|
| 4109 |
+ }) |
|
| 4107 | 4110 |
|
| 4108 | 4111 |
expectedOutput = "options timeout:3" |
| 4109 |
- out, _ = dockerCmd(c, "run", "--dns-opt=timeout:3", "--net=host", "busybox", "cat", "/etc/resolv.conf") |
|
| 4110 |
- c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
|
|
| 4112 |
+ cli.DockerCmd(c, "run", "--dns-opt=timeout:3", "--net=host", "busybox", "cat", "/etc/resolv.conf").Assert(c, icmd.Expected{
|
|
| 4113 |
+ Out: expectedOutput, |
|
| 4114 |
+ }) |
|
| 4111 | 4115 |
|
| 4112 | 4116 |
expectedOutput1 := "nameserver 1.2.3.4" |
| 4113 | 4117 |
expectedOutput2 := "search example.com" |
| 4114 | 4118 |
expectedOutput3 := "options timeout:3" |
| 4115 |
- out, _ = dockerCmd(c, "run", "--dns=1.2.3.4", "--dns-search=example.com", "--dns-opt=timeout:3", "--net=host", "busybox", "cat", "/etc/resolv.conf") |
|
| 4119 |
+ out := cli.DockerCmd(c, "run", "--dns=1.2.3.4", "--dns-search=example.com", "--dns-opt=timeout:3", "--net=host", "busybox", "cat", "/etc/resolv.conf").Combined() |
|
| 4116 | 4120 |
c.Assert(out, checker.Contains, expectedOutput1, check.Commentf("Expected '%s', but got %q", expectedOutput1, out))
|
| 4117 | 4121 |
c.Assert(out, checker.Contains, expectedOutput2, check.Commentf("Expected '%s', but got %q", expectedOutput2, out))
|
| 4118 | 4122 |
c.Assert(out, checker.Contains, expectedOutput3, check.Commentf("Expected '%s', but got %q", expectedOutput3, out))
|
| ... | ... |
@@ -4139,25 +4144,24 @@ func (s *DockerSuite) TestRunRmAndWait(c *check.C) {
|
| 4139 | 4139 |
// Test that auto-remove is performed by the daemon (API 1.25 and above) |
| 4140 | 4140 |
func (s *DockerSuite) TestRunRm(c *check.C) {
|
| 4141 | 4141 |
name := "miss-me-when-im-gone" |
| 4142 |
- dockerCmd(c, "run", "--name="+name, "--rm", "busybox") |
|
| 4142 |
+ cli.DockerCmd(c, "run", "--name="+name, "--rm", "busybox") |
|
| 4143 | 4143 |
|
| 4144 |
- _, err := inspectFieldWithError(name, "name") |
|
| 4145 |
- c.Assert(err, checker.Not(check.IsNil)) |
|
| 4146 |
- c.Assert(err.Error(), checker.Contains, "No such object: "+name) |
|
| 4144 |
+ cli.Docker(cli.Inspect(name), cli.Format(".name")).Assert(c, icmd.Expected{
|
|
| 4145 |
+ ExitCode: 1, |
|
| 4146 |
+ Err: "No such object: " + name, |
|
| 4147 |
+ }) |
|
| 4147 | 4148 |
} |
| 4148 | 4149 |
|
| 4149 | 4150 |
// Test that auto-remove is performed by the client on API versions that do not support daemon-side api-remove (API < 1.25) |
| 4150 | 4151 |
func (s *DockerSuite) TestRunRmPre125Api(c *check.C) {
|
| 4151 | 4152 |
name := "miss-me-when-im-gone" |
| 4152 |
- result := icmd.RunCmd(icmd.Cmd{
|
|
| 4153 |
- Command: binaryWithArgs("run", "--name="+name, "--rm", "busybox"),
|
|
| 4154 |
- Env: appendBaseEnv(false, "DOCKER_API_VERSION=1.24"), |
|
| 4155 |
- }) |
|
| 4156 |
- c.Assert(result, icmd.Matches, icmd.Success) |
|
| 4153 |
+ envs := appendBaseEnv(false, "DOCKER_API_VERSION=1.24") |
|
| 4154 |
+ cli.Docker(cli.Args("run", "--name="+name, "--rm", "busybox"), cli.WithEnvironmentVariables(envs...)).Assert(c, icmd.Success)
|
|
| 4157 | 4155 |
|
| 4158 |
- _, err := inspectFieldWithError(name, "name") |
|
| 4159 |
- c.Assert(err, checker.Not(check.IsNil)) |
|
| 4160 |
- c.Assert(err.Error(), checker.Contains, "No such object: "+name) |
|
| 4156 |
+ cli.Docker(cli.Inspect(name), cli.Format(".name")).Assert(c, icmd.Expected{
|
|
| 4157 |
+ ExitCode: 1, |
|
| 4158 |
+ Err: "No such object: " + name, |
|
| 4159 |
+ }) |
|
| 4161 | 4160 |
} |
| 4162 | 4161 |
|
| 4163 | 4162 |
// Test case for #23498 |
| ... | ... |
@@ -17,6 +17,7 @@ import ( |
| 17 | 17 |
"time" |
| 18 | 18 |
|
| 19 | 19 |
"github.com/docker/docker/integration-cli/checker" |
| 20 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 20 | 21 |
"github.com/docker/docker/integration-cli/cli/build" |
| 21 | 22 |
"github.com/docker/docker/pkg/homedir" |
| 22 | 23 |
"github.com/docker/docker/pkg/mount" |
| ... | ... |
@@ -495,11 +496,13 @@ func (s *DockerSuite) TestRunWithKernelMemory(c *check.C) {
|
| 495 | 495 |
testRequires(c, kernelMemorySupport) |
| 496 | 496 |
|
| 497 | 497 |
file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes" |
| 498 |
- stdout, _, _ := dockerCmdWithStdoutStderr(c, "run", "--kernel-memory", "50M", "--name", "test1", "busybox", "cat", file) |
|
| 499 |
- c.Assert(strings.TrimSpace(stdout), checker.Equals, "52428800") |
|
| 498 |
+ cli.DockerCmd(c, "run", "--kernel-memory", "50M", "--name", "test1", "busybox", "cat", file).Assert(c, icmd.Expected{
|
|
| 499 |
+ Out: "52428800", |
|
| 500 |
+ }) |
|
| 500 | 501 |
|
| 501 |
- out := inspectField(c, "test1", "HostConfig.KernelMemory") |
|
| 502 |
- c.Assert(out, check.Equals, "52428800") |
|
| 502 |
+ cli.InspectCmd(c, "test1", cli.Format(".HostConfig.KernelMemory")).Assert(c, icmd.Expected{
|
|
| 503 |
+ Out: "52428800", |
|
| 504 |
+ }) |
|
| 503 | 505 |
} |
| 504 | 506 |
|
| 505 | 507 |
func (s *DockerSuite) TestRunWithInvalidKernelMemory(c *check.C) {
|
| ... | ... |
@@ -531,8 +534,9 @@ func (s *DockerSuite) TestRunWithCPUShares(c *check.C) {
|
| 531 | 531 |
func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *check.C) {
|
| 532 | 532 |
testRequires(c, cpuShare) |
| 533 | 533 |
testRequires(c, memoryLimitSupport) |
| 534 |
- out, _, _ := dockerCmdWithStdoutStderr(c, "run", "--cpu-shares", "1000", "-m", "32m", "busybox", "echo", "test") |
|
| 535 |
- c.Assert(out, checker.Equals, "test\n", check.Commentf("container should've printed 'test'"))
|
|
| 534 |
+ cli.DockerCmd(c, "run", "--cpu-shares", "1000", "-m", "32m", "busybox", "echo", "test").Assert(c, icmd.Expected{
|
|
| 535 |
+ Out: "test\n", |
|
| 536 |
+ }) |
|
| 536 | 537 |
} |
| 537 | 538 |
|
| 538 | 539 |
func (s *DockerSuite) TestRunWithCpusetCpus(c *check.C) {
|
| ... | ... |
@@ -629,11 +633,12 @@ func (s *DockerSuite) TestRunWithMemoryLimit(c *check.C) {
|
| 629 | 629 |
testRequires(c, memoryLimitSupport) |
| 630 | 630 |
|
| 631 | 631 |
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" |
| 632 |
- stdout, _, _ := dockerCmdWithStdoutStderr(c, "run", "-m", "32M", "--name", "test", "busybox", "cat", file) |
|
| 633 |
- c.Assert(strings.TrimSpace(stdout), checker.Equals, "33554432") |
|
| 634 |
- |
|
| 635 |
- out := inspectField(c, "test", "HostConfig.Memory") |
|
| 636 |
- c.Assert(out, check.Equals, "33554432") |
|
| 632 |
+ cli.DockerCmd(c, "run", "-m", "32M", "--name", "test", "busybox", "cat", file).Assert(c, icmd.Expected{
|
|
| 633 |
+ Out: "33554432", |
|
| 634 |
+ }) |
|
| 635 |
+ cli.InspectCmd(c, "test", cli.Format(".HostConfig.Memory")).Assert(c, icmd.Expected{
|
|
| 636 |
+ Out: "33554432", |
|
| 637 |
+ }) |
|
| 637 | 638 |
} |
| 638 | 639 |
|
| 639 | 640 |
// TestRunWithoutMemoryswapLimit sets memory limit and disables swap |
| ... | ... |
@@ -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 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 10 | 11 |
"github.com/go-check/check" |
| 11 | 12 |
) |
| ... | ... |
@@ -42,18 +43,15 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
|
| 42 | 42 |
// gh#8555: Exit code should be passed through when using start -a |
| 43 | 43 |
func (s *DockerSuite) TestStartAttachCorrectExitCode(c *check.C) {
|
| 44 | 44 |
testRequires(c, DaemonIsLinux) |
| 45 |
- out, _, _ := dockerCmdWithStdoutStderr(c, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1") |
|
| 45 |
+ out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1").Stdout() |
|
| 46 | 46 |
out = strings.TrimSpace(out) |
| 47 | 47 |
|
| 48 | 48 |
// make sure the container has exited before trying the "start -a" |
| 49 |
- dockerCmd(c, "wait", out) |
|
| 50 |
- |
|
| 51 |
- startOut, exitCode, err := dockerCmdWithError("start", "-a", out)
|
|
| 52 |
- // start command should fail |
|
| 53 |
- c.Assert(err, checker.NotNil, check.Commentf("startOut: %s", startOut))
|
|
| 54 |
- // start -a did not respond with proper exit code |
|
| 55 |
- c.Assert(exitCode, checker.Equals, 1, check.Commentf("startOut: %s", startOut))
|
|
| 49 |
+ cli.DockerCmd(c, "wait", out) |
|
| 56 | 50 |
|
| 51 |
+ cli.Docker(cli.Args("start", "-a", out)).Assert(c, icmd.Expected{
|
|
| 52 |
+ ExitCode: 1, |
|
| 53 |
+ }) |
|
| 57 | 54 |
} |
| 58 | 55 |
|
| 59 | 56 |
func (s *DockerSuite) TestStartAttachSilent(c *check.C) {
|
| ... | ... |
@@ -58,7 +58,7 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
| 58 | 58 |
return sw.Spec |
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 |
- cli.Docker(cli.Cmd("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s"),
|
|
| 61 |
+ cli.Docker(cli.Args("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s"),
|
|
| 62 | 62 |
cli.Daemon(d.Daemon)).Assert(c, icmd.Success) |
| 63 | 63 |
|
| 64 | 64 |
spec := getSpec() |
| ... | ... |
@@ -67,7 +67,7 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
| 67 | 67 |
|
| 68 | 68 |
c.Assert(d.Leave(true), checker.IsNil) |
| 69 | 69 |
time.Sleep(500 * time.Millisecond) // https://github.com/docker/swarmkit/issues/1421 |
| 70 |
- cli.Docker(cli.Cmd("swarm", "init"), cli.Daemon(d.Daemon)).Assert(c, icmd.Success)
|
|
| 70 |
+ cli.Docker(cli.Args("swarm", "init"), cli.Daemon(d.Daemon)).Assert(c, icmd.Success)
|
|
| 71 | 71 |
|
| 72 | 72 |
spec = getSpec() |
| 73 | 73 |
c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 90*24*time.Hour) |
| ... | ... |
@@ -77,12 +77,12 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
|
| 77 | 77 |
func (s *DockerSwarmSuite) TestSwarmInitIPv6(c *check.C) {
|
| 78 | 78 |
testRequires(c, IPv6) |
| 79 | 79 |
d1 := s.AddDaemon(c, false, false) |
| 80 |
- cli.Docker(cli.Cmd("swarm", "init", "--listen-add", "::1"), cli.Daemon(d1.Daemon)).Assert(c, icmd.Success)
|
|
| 80 |
+ cli.Docker(cli.Args("swarm", "init", "--listen-add", "::1"), cli.Daemon(d1.Daemon)).Assert(c, icmd.Success)
|
|
| 81 | 81 |
|
| 82 | 82 |
d2 := s.AddDaemon(c, false, false) |
| 83 |
- cli.Docker(cli.Cmd("swarm", "join", "::1"), cli.Daemon(d2.Daemon)).Assert(c, icmd.Success)
|
|
| 83 |
+ cli.Docker(cli.Args("swarm", "join", "::1"), cli.Daemon(d2.Daemon)).Assert(c, icmd.Success)
|
|
| 84 | 84 |
|
| 85 |
- out := cli.Docker(cli.Cmd("info"), cli.Daemon(d2.Daemon)).Assert(c, icmd.Success).Combined()
|
|
| 85 |
+ out := cli.Docker(cli.Args("info"), cli.Daemon(d2.Daemon)).Assert(c, icmd.Success).Combined()
|
|
| 86 | 86 |
c.Assert(out, checker.Contains, "Swarm: active") |
| 87 | 87 |
} |
| 88 | 88 |
|
| ... | ... |
@@ -7,6 +7,7 @@ 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/pkg/parsers/kernel" |
| 11 | 12 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 12 | 13 |
"github.com/go-check/check" |
| ... | ... |
@@ -368,24 +369,23 @@ func (s *DockerSuite) TestDockerNetworkMacVlanBridgeNilParent(c *check.C) {
|
| 368 | 368 |
func (s *DockerSuite) TestDockerNetworkMacVlanBridgeInternalMode(c *check.C) {
|
| 369 | 369 |
// macvlan bridge mode --internal containers can communicate inside the network but not externally |
| 370 | 370 |
testRequires(c, DaemonIsLinux, macvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
| 371 |
- dockerCmd(c, "network", "create", "--driver=macvlan", "--internal", "dm-internal") |
|
| 371 |
+ cli.DockerCmd(c, "network", "create", "--driver=macvlan", "--internal", "dm-internal") |
|
| 372 | 372 |
assertNwIsAvailable(c, "dm-internal") |
| 373 | 373 |
nr := getNetworkResource(c, "dm-internal") |
| 374 | 374 |
c.Assert(nr.Internal, checker.True) |
| 375 | 375 |
|
| 376 | 376 |
// start two containers on the same subnet |
| 377 |
- dockerCmd(c, "run", "-d", "--net=dm-internal", "--name=first", "busybox", "top") |
|
| 377 |
+ cli.DockerCmd(c, "run", "-d", "--net=dm-internal", "--name=first", "busybox", "top") |
|
| 378 | 378 |
c.Assert(waitRun("first"), check.IsNil)
|
| 379 |
- dockerCmd(c, "run", "-d", "--net=dm-internal", "--name=second", "busybox", "top") |
|
| 379 |
+ cli.DockerCmd(c, "run", "-d", "--net=dm-internal", "--name=second", "busybox", "top") |
|
| 380 | 380 |
c.Assert(waitRun("second"), check.IsNil)
|
| 381 | 381 |
|
| 382 | 382 |
// access outside of the network should fail |
| 383 |
- result := dockerCmdWithTimeout(time.Second, "exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8") |
|
| 383 |
+ result := cli.Docker(cli.Args("exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8"), cli.WithTimeout(time.Second))
|
|
| 384 | 384 |
c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true})
|
| 385 | 385 |
|
| 386 | 386 |
// intra-network communications should succeed |
| 387 |
- _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
|
|
| 388 |
- c.Assert(err, check.IsNil) |
|
| 387 |
+ cli.DockerCmd(c, "exec", "second", "ping", "-c", "1", "first") |
|
| 389 | 388 |
} |
| 390 | 389 |
|
| 391 | 390 |
func (s *DockerSuite) TestDockerNetworkIpvlanL2NilParent(c *check.C) {
|
| ... | ... |
@@ -408,23 +408,22 @@ func (s *DockerSuite) TestDockerNetworkIpvlanL2NilParent(c *check.C) {
|
| 408 | 408 |
func (s *DockerSuite) TestDockerNetworkIpvlanL2InternalMode(c *check.C) {
|
| 409 | 409 |
// ipvlan l2 mode --internal containers can communicate inside the network but not externally |
| 410 | 410 |
testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
| 411 |
- dockerCmd(c, "network", "create", "--driver=ipvlan", "--internal", "di-internal") |
|
| 411 |
+ cli.DockerCmd(c, "network", "create", "--driver=ipvlan", "--internal", "di-internal") |
|
| 412 | 412 |
assertNwIsAvailable(c, "di-internal") |
| 413 | 413 |
nr := getNetworkResource(c, "di-internal") |
| 414 | 414 |
c.Assert(nr.Internal, checker.True) |
| 415 | 415 |
|
| 416 | 416 |
// start two containers on the same subnet |
| 417 |
- dockerCmd(c, "run", "-d", "--net=di-internal", "--name=first", "busybox", "top") |
|
| 417 |
+ cli.DockerCmd(c, "run", "-d", "--net=di-internal", "--name=first", "busybox", "top") |
|
| 418 | 418 |
c.Assert(waitRun("first"), check.IsNil)
|
| 419 |
- dockerCmd(c, "run", "-d", "--net=di-internal", "--name=second", "busybox", "top") |
|
| 419 |
+ cli.DockerCmd(c, "run", "-d", "--net=di-internal", "--name=second", "busybox", "top") |
|
| 420 | 420 |
c.Assert(waitRun("second"), check.IsNil)
|
| 421 | 421 |
|
| 422 | 422 |
// access outside of the network should fail |
| 423 |
- result := dockerCmdWithTimeout(time.Second, "exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8") |
|
| 423 |
+ result := cli.Docker(cli.Args("exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8"), cli.WithTimeout(time.Second))
|
|
| 424 | 424 |
c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true})
|
| 425 | 425 |
// intra-network communications should succeed |
| 426 |
- _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
|
|
| 427 |
- c.Assert(err, check.IsNil) |
|
| 426 |
+ cli.DockerCmd(c, "exec", "second", "ping", "-c", "1", "first") |
|
| 428 | 427 |
} |
| 429 | 428 |
|
| 430 | 429 |
func (s *DockerSuite) TestDockerNetworkIpvlanL3NilParent(c *check.C) {
|
| ... | ... |
@@ -448,24 +447,23 @@ func (s *DockerSuite) TestDockerNetworkIpvlanL3NilParent(c *check.C) {
|
| 448 | 448 |
func (s *DockerSuite) TestDockerNetworkIpvlanL3InternalMode(c *check.C) {
|
| 449 | 449 |
// ipvlan l3 mode --internal containers can communicate inside the network but not externally |
| 450 | 450 |
testRequires(c, DaemonIsLinux, ipvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) |
| 451 |
- dockerCmd(c, "network", "create", "--driver=ipvlan", "--subnet=172.28.230.0/24", |
|
| 451 |
+ cli.DockerCmd(c, "network", "create", "--driver=ipvlan", "--subnet=172.28.230.0/24", |
|
| 452 | 452 |
"--subnet=172.28.220.0/24", "-o", "ipvlan_mode=l3", "--internal", "di-internal-l3") |
| 453 | 453 |
assertNwIsAvailable(c, "di-internal-l3") |
| 454 | 454 |
nr := getNetworkResource(c, "di-internal-l3") |
| 455 | 455 |
c.Assert(nr.Internal, checker.True) |
| 456 | 456 |
|
| 457 | 457 |
// start two containers on separate subnets |
| 458 |
- dockerCmd(c, "run", "-d", "--ip=172.28.220.10", "--net=di-internal-l3", "--name=first", "busybox", "top") |
|
| 458 |
+ cli.DockerCmd(c, "run", "-d", "--ip=172.28.220.10", "--net=di-internal-l3", "--name=first", "busybox", "top") |
|
| 459 | 459 |
c.Assert(waitRun("first"), check.IsNil)
|
| 460 |
- dockerCmd(c, "run", "-d", "--ip=172.28.230.10", "--net=di-internal-l3", "--name=second", "busybox", "top") |
|
| 460 |
+ cli.DockerCmd(c, "run", "-d", "--ip=172.28.230.10", "--net=di-internal-l3", "--name=second", "busybox", "top") |
|
| 461 | 461 |
c.Assert(waitRun("second"), check.IsNil)
|
| 462 | 462 |
|
| 463 | 463 |
// access outside of the network should fail |
| 464 |
- result := dockerCmdWithTimeout(time.Second, "exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8") |
|
| 464 |
+ result := cli.Docker(cli.Args("exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8"), cli.WithTimeout(time.Second))
|
|
| 465 | 465 |
c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true})
|
| 466 | 466 |
// intra-network communications should succeed |
| 467 |
- _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
|
|
| 468 |
- c.Assert(err, check.IsNil) |
|
| 467 |
+ cli.DockerCmd(c, "exec", "second", "ping", "-c", "1", "first") |
|
| 469 | 468 |
} |
| 470 | 469 |
|
| 471 | 470 |
func (s *DockerSuite) TestDockerNetworkMacVlanExistingParent(c *check.C) {
|
| ... | ... |
@@ -79,77 +79,24 @@ func deleteImages(images ...string) error {
|
| 79 | 79 |
return icmd.RunCmd(icmd.Cmd{Command: append(args, images...)}).Error
|
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 |
+// Deprecated: use cli.Docker or cli.DockerCmd |
|
| 82 | 83 |
func dockerCmdWithError(args ...string) (string, int, error) {
|
| 83 |
- if err := validateArgs(args...); err != nil {
|
|
| 84 |
- return "", 0, err |
|
| 85 |
- } |
|
| 86 |
- result := icmd.RunCommand(dockerBinary, args...) |
|
| 84 |
+ result := cli.Docker(cli.Args(args...)) |
|
| 87 | 85 |
if result.Error != nil {
|
| 88 | 86 |
return result.Combined(), result.ExitCode, result.Compare(icmd.Success) |
| 89 | 87 |
} |
| 90 | 88 |
return result.Combined(), result.ExitCode, result.Error |
| 91 | 89 |
} |
| 92 | 90 |
|
| 93 |
-func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) {
|
|
| 94 |
- if err := validateArgs(args...); err != nil {
|
|
| 95 |
- c.Fatalf(err.Error()) |
|
| 96 |
- } |
|
| 97 |
- |
|
| 98 |
- result := icmd.RunCommand(dockerBinary, args...) |
|
| 99 |
- c.Assert(result, icmd.Matches, icmd.Success) |
|
| 100 |
- return result.Stdout(), result.Stderr(), result.ExitCode |
|
| 101 |
-} |
|
| 102 |
- |
|
| 91 |
+// Deprecated: use cli.Docker or cli.DockerCmd |
|
| 103 | 92 |
func dockerCmd(c *check.C, args ...string) (string, int) {
|
| 104 |
- if err := validateArgs(args...); err != nil {
|
|
| 105 |
- c.Fatalf(err.Error()) |
|
| 106 |
- } |
|
| 107 |
- result := icmd.RunCommand(dockerBinary, args...) |
|
| 108 |
- c.Assert(result, icmd.Matches, icmd.Success) |
|
| 93 |
+ result := cli.DockerCmd(c, args...) |
|
| 109 | 94 |
return result.Combined(), result.ExitCode |
| 110 | 95 |
} |
| 111 | 96 |
|
| 97 |
+// Deprecated: use cli.Docker or cli.DockerCmd |
|
| 112 | 98 |
func dockerCmdWithResult(args ...string) *icmd.Result {
|
| 113 |
- return icmd.RunCommand(dockerBinary, args...) |
|
| 114 |
-} |
|
| 115 |
- |
|
| 116 |
-func binaryWithArgs(args ...string) []string {
|
|
| 117 |
- return append([]string{dockerBinary}, args...)
|
|
| 118 |
-} |
|
| 119 |
- |
|
| 120 |
-// execute a docker command with a timeout |
|
| 121 |
-func dockerCmdWithTimeout(timeout time.Duration, args ...string) *icmd.Result {
|
|
| 122 |
- if err := validateArgs(args...); err != nil {
|
|
| 123 |
- return &icmd.Result{Error: err}
|
|
| 124 |
- } |
|
| 125 |
- return icmd.RunCmd(icmd.Cmd{Command: binaryWithArgs(args...), Timeout: timeout})
|
|
| 126 |
-} |
|
| 127 |
- |
|
| 128 |
-// execute a docker command in a directory |
|
| 129 |
-func dockerCmdInDir(c *check.C, path string, args ...string) (string, int, error) {
|
|
| 130 |
- if err := validateArgs(args...); err != nil {
|
|
| 131 |
- c.Fatalf(err.Error()) |
|
| 132 |
- } |
|
| 133 |
- result := icmd.RunCmd(icmd.Cmd{Command: binaryWithArgs(args...), Dir: path})
|
|
| 134 |
- return result.Combined(), result.ExitCode, result.Error |
|
| 135 |
-} |
|
| 136 |
- |
|
| 137 |
-// validateArgs is a checker to ensure tests are not running commands which are |
|
| 138 |
-// not supported on platforms. Specifically on Windows this is 'busybox top'. |
|
| 139 |
-func validateArgs(args ...string) error {
|
|
| 140 |
- if testEnv.DaemonPlatform() != "windows" {
|
|
| 141 |
- return nil |
|
| 142 |
- } |
|
| 143 |
- foundBusybox := -1 |
|
| 144 |
- for key, value := range args {
|
|
| 145 |
- if strings.ToLower(value) == "busybox" {
|
|
| 146 |
- foundBusybox = key |
|
| 147 |
- } |
|
| 148 |
- if (foundBusybox != -1) && (key == foundBusybox+1) && (strings.ToLower(value) == "top") {
|
|
| 149 |
- return errors.New("cannot use 'busybox top' in tests on Windows. Use runSleepingContainer()")
|
|
| 150 |
- } |
|
| 151 |
- } |
|
| 152 |
- return nil |
|
| 99 |
+ return cli.Docker(cli.Args(args...)) |
|
| 153 | 100 |
} |
| 154 | 101 |
|
| 155 | 102 |
func findContainerIP(c *check.C, id string, network string) string {
|
| ... | ... |
@@ -391,6 +338,7 @@ func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{
|
| 391 | 391 |
} |
| 392 | 392 |
} |
| 393 | 393 |
|
| 394 |
+// Deprecated: use cli.Inspect |
|
| 394 | 395 |
func inspectFilter(name, filter string) (string, error) {
|
| 395 | 396 |
format := fmt.Sprintf("{{%s}}", filter)
|
| 396 | 397 |
result := icmd.RunCommand(dockerBinary, "inspect", "-f", format, name) |
| ... | ... |
@@ -400,10 +348,12 @@ func inspectFilter(name, filter string) (string, error) {
|
| 400 | 400 |
return strings.TrimSpace(result.Combined()), nil |
| 401 | 401 |
} |
| 402 | 402 |
|
| 403 |
+// Deprecated: use cli.Inspect |
|
| 403 | 404 |
func inspectFieldWithError(name, field string) (string, error) {
|
| 404 | 405 |
return inspectFilter(name, fmt.Sprintf(".%s", field))
|
| 405 | 406 |
} |
| 406 | 407 |
|
| 408 |
+// Deprecated: use cli.Inspect |
|
| 407 | 409 |
func inspectField(c *check.C, name, field string) string {
|
| 408 | 410 |
out, err := inspectFilter(name, fmt.Sprintf(".%s", field))
|
| 409 | 411 |
if c != nil {
|
| ... | ... |
@@ -412,6 +362,7 @@ func inspectField(c *check.C, name, field string) string {
|
| 412 | 412 |
return out |
| 413 | 413 |
} |
| 414 | 414 |
|
| 415 |
+// Deprecated: use cli.Inspect |
|
| 415 | 416 |
func inspectFieldJSON(c *check.C, name, field string) string {
|
| 416 | 417 |
out, err := inspectFilter(name, fmt.Sprintf("json .%s", field))
|
| 417 | 418 |
if c != nil {
|
| ... | ... |
@@ -420,6 +371,7 @@ func inspectFieldJSON(c *check.C, name, field string) string {
|
| 420 | 420 |
return out |
| 421 | 421 |
} |
| 422 | 422 |
|
| 423 |
+// Deprecated: use cli.Inspect |
|
| 423 | 424 |
func inspectFieldMap(c *check.C, name, path, field string) string {
|
| 424 | 425 |
out, err := inspectFilter(name, fmt.Sprintf("index .%s %q", path, field))
|
| 425 | 426 |
if c != nil {
|
| ... | ... |
@@ -428,6 +380,7 @@ func inspectFieldMap(c *check.C, name, path, field string) string {
|
| 428 | 428 |
return out |
| 429 | 429 |
} |
| 430 | 430 |
|
| 431 |
+// Deprecated: use cli.Inspect |
|
| 431 | 432 |
func inspectMountSourceField(name, destination string) (string, error) {
|
| 432 | 433 |
m, err := inspectMountPoint(name, destination) |
| 433 | 434 |
if err != nil {
|
| ... | ... |
@@ -436,6 +389,7 @@ func inspectMountSourceField(name, destination string) (string, error) {
|
| 436 | 436 |
return m.Source, nil |
| 437 | 437 |
} |
| 438 | 438 |
|
| 439 |
+// Deprecated: use cli.Inspect |
|
| 439 | 440 |
func inspectMountPoint(name, destination string) (types.MountPoint, error) {
|
| 440 | 441 |
out, err := inspectFilter(name, "json .Mounts") |
| 441 | 442 |
if err != nil {
|
| ... | ... |
@@ -447,6 +401,7 @@ func inspectMountPoint(name, destination string) (types.MountPoint, error) {
|
| 447 | 447 |
|
| 448 | 448 |
var errMountNotFound = errors.New("mount point not found")
|
| 449 | 449 |
|
| 450 |
+// Deprecated: use cli.Inspect |
|
| 450 | 451 |
func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
|
| 451 | 452 |
var mp []types.MountPoint |
| 452 | 453 |
if err := json.Unmarshal([]byte(j), &mp); err != nil {
|
| ... | ... |
@@ -468,6 +423,7 @@ func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
|
| 468 | 468 |
return *m, nil |
| 469 | 469 |
} |
| 470 | 470 |
|
| 471 |
+// Deprecated: use cli.Inspect |
|
| 471 | 472 |
func inspectImage(c *check.C, name, filter string) string {
|
| 472 | 473 |
args := []string{"inspect", "--type", "image"}
|
| 473 | 474 |
if filter != "" {
|