summaryrefslogtreecommitdiff
path: root/integration-cli/cli
diff options
context:
space:
mode:
authorVincent Demeester <vincent@sbr.pm>2017-03-27 17:12:48 +0200
committerVincent Demeester <vincent@sbr.pm>2017-03-28 15:17:31 +0200
commiteeaa6c96d83575da765dfc626c2c73d8a29dda32 (patch)
tree9c921a7f79c85e9998d37130a087f5263b193a7d /integration-cli/cli
parentdc1f036772439d08c81cd8eef92d661b7fafbd0e (diff)
downloaddocker-eeaa6c96d83575da765dfc626c2c73d8a29dda32.tar.gz
[test-integration] Migrate some more tests to `cli` package
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>
Diffstat (limited to 'integration-cli/cli')
-rw-r--r--integration-cli/cli/cli.go59
1 files changed, 54 insertions, 5 deletions
diff --git a/integration-cli/cli/cli.go b/integration-cli/cli/cli.go
index 5bd0b8ce6d..b1f22dbfc7 100644
--- a/integration-cli/cli/cli.go
+++ b/integration-cli/cli/cli.go
@@ -2,12 +2,15 @@ package cli
import (
"fmt"
+ "io"
+ "strings"
"sync"
"time"
"github.com/docker/docker/integration-cli/daemon"
"github.com/docker/docker/integration-cli/environment"
icmd "github.com/docker/docker/pkg/testutil/cmd"
+ "github.com/pkg/errors"
)
var (
@@ -40,8 +43,8 @@ type testingT interface {
}
// DockerCmd executes the specified docker command and expect a success
-func DockerCmd(t testingT, command string, args ...string) *icmd.Result {
- return Docker(Cmd(command, args...)).Assert(t, icmd.Success)
+func DockerCmd(t testingT, args ...string) *icmd.Result {
+ return Docker(Args(args...)).Assert(t, icmd.Success)
}
// BuildCmd executes the specified docker build command and expect a success
@@ -63,9 +66,32 @@ func Docker(cmd icmd.Cmd, cmdOperators ...CmdOperator) *icmd.Result {
}
}
appendDocker(&cmd)
+ if err := validateArgs(cmd.Command...); err != nil {
+ return &icmd.Result{
+ Error: err,
+ }
+ }
return icmd.RunCmd(cmd)
}
+// validateArgs is a checker to ensure tests are not running commands which are
+// not supported on platforms. Specifically on Windows this is 'busybox top'.
+func validateArgs(args ...string) error {
+ if testEnv.DaemonPlatform() != "windows" {
+ return nil
+ }
+ foundBusybox := -1
+ for key, value := range args {
+ if strings.ToLower(value) == "busybox" {
+ foundBusybox = key
+ }
+ if (foundBusybox != -1) && (key == foundBusybox+1) && (strings.ToLower(value) == "top") {
+ return errors.New("cannot use 'busybox top' in tests on Windows. Use runSleepingContainer()")
+ }
+ }
+ return nil
+}
+
// Build executes the specified docker build command
func Build(name string) icmd.Cmd {
return icmd.Command("build", "-t", name)
@@ -91,9 +117,16 @@ func appendDocker(cmd *icmd.Cmd) {
cmd.Command = append([]string{testEnv.DockerBinary()}, cmd.Command...)
}
-// Cmd build an icmd.Cmd struct from the specified command and arguments
-func Cmd(command string, args ...string) icmd.Cmd {
- return icmd.Command(command, args...)
+// Args build an icmd.Cmd struct from the specified arguments
+func Args(args ...string) icmd.Cmd {
+ switch len(args) {
+ case 0:
+ return icmd.Cmd{}
+ case 1:
+ return icmd.Command(args[0])
+ default:
+ return icmd.Command(args[0], args[1:]...)
+ }
}
// Daemon points to the specified daemon
@@ -127,3 +160,19 @@ func WithFlags(flags ...string) func(*icmd.Cmd) func() {
return nil
}
}
+
+// InDir sets the folder in which the command should be executed
+func InDir(path string) func(*icmd.Cmd) func() {
+ return func(cmd *icmd.Cmd) func() {
+ cmd.Dir = path
+ return nil
+ }
+}
+
+// WithStdout sets the standard output writer of the command
+func WithStdout(writer io.Writer) func(*icmd.Cmd) func() {
+ return func(cmd *icmd.Cmd) func() {
+ cmd.Stdout = writer
+ return nil
+ }
+}