Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -39,7 +39,7 @@ func (s *DockerSuite) TestEventsApiBackwardsCompatible(c *check.C) {
|
| 39 | 39 |
since := daemonTime(c).Unix() |
| 40 | 40 |
ts := strconv.FormatInt(since, 10) |
| 41 | 41 |
|
| 42 |
- out, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") |
|
| 42 |
+ out, _ := runSleepingContainer(c, "--name=foo", "-d") |
|
| 43 | 43 |
containerID := strings.TrimSpace(out) |
| 44 | 44 |
c.Assert(waitRun(containerID), checker.IsNil) |
| 45 | 45 |
|
| ... | ... |
@@ -439,7 +439,7 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) {
|
| 439 | 439 |
func (s *DockerSuite) TestEventsResize(c *check.C) {
|
| 440 | 440 |
since := daemonTime(c).Unix() |
| 441 | 441 |
|
| 442 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "top") |
|
| 442 |
+ out, _ := runSleepingContainer(c, "-d") |
|
| 443 | 443 |
cID := strings.TrimSpace(out) |
| 444 | 444 |
c.Assert(waitRun(cID), checker.IsNil) |
| 445 | 445 |
|
| ... | ... |
@@ -273,7 +273,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
|
| 273 | 273 |
//Both the container and image are named busybox. docker inspect will fetch container |
| 274 | 274 |
//JSON SizeRw and SizeRootFs field. If there is no flag --size/-s, there are no size fields. |
| 275 | 275 |
|
| 276 |
- dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") |
|
| 276 |
+ runSleepingContainer(c, "--name=busybox", "-d") |
|
| 277 | 277 |
|
| 278 | 278 |
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
| 279 | 279 |
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") |
| ... | ... |
@@ -281,7 +281,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
|
| 281 | 281 |
} |
| 282 | 282 |
|
| 283 | 283 |
func (s *DockerSuite) TestInspectSizeFlagContainer(c *check.C) {
|
| 284 |
- dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") |
|
| 284 |
+ runSleepingContainer(c, "--name=busybox", "-d") |
|
| 285 | 285 |
|
| 286 | 286 |
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
| 287 | 287 |
out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox") |
| ... | ... |
@@ -292,7 +292,7 @@ func (s *DockerSuite) TestInspectSizeFlagContainer(c *check.C) {
|
| 292 | 292 |
} |
| 293 | 293 |
|
| 294 | 294 |
func (s *DockerSuite) TestInspectSizeFlagImage(c *check.C) {
|
| 295 |
- dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") |
|
| 295 |
+ runSleepingContainer(c, "-d") |
|
| 296 | 296 |
|
| 297 | 297 |
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
| 298 | 298 |
out, _, err := dockerCmdWithError("inspect", "-s", "--type=image", formatStr, "busybox")
|
| ... | ... |
@@ -303,10 +303,10 @@ func (s *DockerSuite) TestInspectSizeFlagImage(c *check.C) {
|
| 303 | 303 |
c.Assert(out, checker.Contains, "Template parsing error") |
| 304 | 304 |
} |
| 305 | 305 |
|
| 306 |
-func (s *DockerSuite) TestInspectTempateError(c *check.C) {
|
|
| 306 |
+func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
|
|
| 307 | 307 |
// Template parsing error for both the container and image. |
| 308 | 308 |
|
| 309 |
- dockerCmd(c, "run", "--name=container1", "-d", "busybox", "top") |
|
| 309 |
+ runSleepingContainer(c, "--name=container1", "-d") |
|
| 310 | 310 |
|
| 311 | 311 |
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1")
|
| 312 | 312 |
c.Assert(err, check.Not(check.IsNil)) |
| ... | ... |
@@ -318,7 +318,7 @@ func (s *DockerSuite) TestInspectTempateError(c *check.C) {
|
| 318 | 318 |
} |
| 319 | 319 |
|
| 320 | 320 |
func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
|
| 321 |
- dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") |
|
| 321 |
+ runSleepingContainer(c, "--name=busybox", "-d") |
|
| 322 | 322 |
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.HostConfig.Dns}}'", "busybox")
|
| 323 | 323 |
|
| 324 | 324 |
c.Assert(err, check.IsNil) |
| ... | ... |
@@ -337,8 +337,8 @@ func (s *DockerSuite) TestInspectByPrefix(c *check.C) {
|
| 337 | 337 |
} |
| 338 | 338 |
|
| 339 | 339 |
func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) {
|
| 340 |
- dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") |
|
| 341 |
- dockerCmd(c, "run", "--name=not-shown", "-d", "busybox", "top") |
|
| 340 |
+ runSleepingContainer(c, "--name=busybox", "-d") |
|
| 341 |
+ runSleepingContainer(c, "--name=not-shown", "-d") |
|
| 342 | 342 |
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.Name}}'", "busybox", "missing", "not-shown")
|
| 343 | 343 |
|
| 344 | 344 |
c.Assert(err, checker.Not(check.IsNil)) |
| ... | ... |
@@ -872,32 +872,68 @@ func pullImageIfNotExist(image string) error {
|
| 872 | 872 |
} |
| 873 | 873 |
|
| 874 | 874 |
func dockerCmdWithError(args ...string) (string, int, error) {
|
| 875 |
+ if err := validateArgs(args...); err != nil {
|
|
| 876 |
+ return "", 0, err |
|
| 877 |
+ } |
|
| 875 | 878 |
return integration.DockerCmdWithError(dockerBinary, args...) |
| 876 | 879 |
} |
| 877 | 880 |
|
| 878 | 881 |
func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) {
|
| 882 |
+ if err := validateArgs(args...); err != nil {
|
|
| 883 |
+ c.Fatalf(err.Error()) |
|
| 884 |
+ } |
|
| 879 | 885 |
return integration.DockerCmdWithStdoutStderr(dockerBinary, c, args...) |
| 880 | 886 |
} |
| 881 | 887 |
|
| 882 | 888 |
func dockerCmd(c *check.C, args ...string) (string, int) {
|
| 889 |
+ if err := validateArgs(args...); err != nil {
|
|
| 890 |
+ c.Fatalf(err.Error()) |
|
| 891 |
+ } |
|
| 883 | 892 |
return integration.DockerCmd(dockerBinary, c, args...) |
| 884 | 893 |
} |
| 885 | 894 |
|
| 886 | 895 |
// execute a docker command with a timeout |
| 887 | 896 |
func dockerCmdWithTimeout(timeout time.Duration, args ...string) (string, int, error) {
|
| 897 |
+ if err := validateArgs(args...); err != nil {
|
|
| 898 |
+ return "", 0, err |
|
| 899 |
+ } |
|
| 888 | 900 |
return integration.DockerCmdWithTimeout(dockerBinary, timeout, args...) |
| 889 | 901 |
} |
| 890 | 902 |
|
| 891 | 903 |
// execute a docker command in a directory |
| 892 | 904 |
func dockerCmdInDir(c *check.C, path string, args ...string) (string, int, error) {
|
| 905 |
+ if err := validateArgs(args...); err != nil {
|
|
| 906 |
+ c.Fatalf(err.Error()) |
|
| 907 |
+ } |
|
| 893 | 908 |
return integration.DockerCmdInDir(dockerBinary, path, args...) |
| 894 | 909 |
} |
| 895 | 910 |
|
| 896 | 911 |
// execute a docker command in a directory with a timeout |
| 897 | 912 |
func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...string) (string, int, error) {
|
| 913 |
+ if err := validateArgs(args...); err != nil {
|
|
| 914 |
+ return "", 0, err |
|
| 915 |
+ } |
|
| 898 | 916 |
return integration.DockerCmdInDirWithTimeout(dockerBinary, timeout, path, args...) |
| 899 | 917 |
} |
| 900 | 918 |
|
| 919 |
+// validateArgs is a checker to ensure tests are not running commands which are |
|
| 920 |
+// not supported on platforms. Specifically on Windows this is 'busybox top'. |
|
| 921 |
+func validateArgs(args ...string) error {
|
|
| 922 |
+ if daemonPlatform != "windows" {
|
|
| 923 |
+ return nil |
|
| 924 |
+ } |
|
| 925 |
+ foundBusybox := -1 |
|
| 926 |
+ for key, value := range args {
|
|
| 927 |
+ if strings.ToLower(value) == "busybox" {
|
|
| 928 |
+ foundBusybox = key |
|
| 929 |
+ } |
|
| 930 |
+ if (foundBusybox != -1) && (key == foundBusybox+1) && (strings.ToLower(value) == "top") {
|
|
| 931 |
+ return errors.New("Cannot use 'busybox top' in tests on Windows. Use runSleepingContainer()")
|
|
| 932 |
+ } |
|
| 933 |
+ } |
|
| 934 |
+ return nil |
|
| 935 |
+} |
|
| 936 |
+ |
|
| 901 | 937 |
// find the State.ExitCode in container metadata |
| 902 | 938 |
func findContainerExitCode(c *check.C, name string, vargs ...string) string {
|
| 903 | 939 |
args := append(vargs, "inspect", "--format='{{ .State.ExitCode }} {{ .State.Error }}'", name)
|