diff --git a/integration-cli/docker_api_volumes_test.go b/integration-cli/docker_api_volumes_test.go index eab19091ce..9f698eb495 100644 --- a/integration-cli/docker_api_volumes_test.go +++ b/integration-cli/docker_api_volumes_test.go @@ -11,10 +11,7 @@ import ( ) func (s *DockerSuite) TestVolumesApiList(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "run", "-d", "-v", prefix+"/foo", "busybox") status, b, err := sockRequest("GET", "/volumes", nil) @@ -43,10 +40,7 @@ func (s *DockerSuite) TestVolumesApiCreate(c *check.C) { } func (s *DockerSuite) TestVolumesApiRemove(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "run", "-d", "-v", prefix+"/foo", "--name=test", "busybox") status, b, err := sockRequest("GET", "/volumes", nil) diff --git a/integration-cli/docker_cli_create_test.go b/integration-cli/docker_cli_create_test.go index ef14d51738..657c3fd6a2 100644 --- a/integration-cli/docker_cli_create_test.go +++ b/integration-cli/docker_cli_create_test.go @@ -429,12 +429,8 @@ func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) { c.Skip("Fails on Windows CI") } name := "foo" - slash := "/" - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - slash = `/` - } + + prefix, slash := getPrefixAndSlashFromDaemonPlatform() dir := prefix + slash + "home" + slash + "foo" + slash + "bar" dockerCmd(c, "create", "--name", name, "-w", dir, "busybox") diff --git a/integration-cli/docker_cli_rm_test.go b/integration-cli/docker_cli_rm_test.go index 088909ed4d..86e1089a57 100644 --- a/integration-cli/docker_cli_rm_test.go +++ b/integration-cli/docker_cli_rm_test.go @@ -12,12 +12,7 @@ import ( func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) { testRequires(c, SameHostDaemon) - prefix := "" - slash := "/" - if daemonPlatform == "windows" { - prefix = "c:" - slash = `\` - } + prefix, slash := getPrefixAndSlashFromDaemonPlatform() tempDir, err := ioutil.TempDir("", "test-rm-container-with-removed-volume-") if err != nil { @@ -34,12 +29,7 @@ func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) { } func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) { - prefix := "" - slash := "/" - if daemonPlatform == "windows" { - prefix = "c:" - slash = `\` - } + prefix, slash := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "run", "--name", "foo", "-v", prefix+slash+"srv", "busybox", "true") diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 1999005b77..f09e3f67c8 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2102,10 +2102,7 @@ func (s *DockerSuite) TestRunAllocatePortInReservedRange(c *check.C) { func (s *DockerSuite) TestRunMountOrdering(c *check.C) { // TODO Windows: Post TP4. Updated, but Windows does not support nested mounts currently. testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() tmpDir, err := ioutil.TempDir("", "docker_nested_mount_test") if err != nil { @@ -2150,10 +2147,7 @@ func (s *DockerSuite) TestRunMountOrdering(c *check.C) { func (s *DockerSuite) TestRunReuseBindVolumeThatIsSymlink(c *check.C) { // Not applicable on Windows as Windows does not support volumes testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() tmpDir, err := ioutil.TempDir(os.TempDir(), "testlink") if err != nil { @@ -2236,12 +2230,7 @@ func (s *DockerSuite) TestRunNoOutputFromPullInStdout(c *check.C) { func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) { testRequires(c, SameHostDaemon) - prefix := "" - slash := `/` - if daemonPlatform == "windows" { - prefix = "c:" - slash = `\` - } + prefix, slash := getPrefixAndSlashFromDaemonPlatform() if _, err := buildImage("run_volumes_clean_paths", `FROM busybox VOLUME `+prefix+`/foo/`, @@ -2802,10 +2791,7 @@ func (s *DockerSuite) TestRunContainerWithReadonlyRootfsWithAddHostFlag(c *check } func (s *DockerSuite) TestRunVolumesFromRestartAfterRemoved(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "run", "-d", "--name", "voltest", "-v", prefix+"/foo", "busybox", "sleep", "60") dockerCmd(c, "run", "-d", "--name", "restarter", "--volumes-from", "voltest", "busybox", "sleep", "60") @@ -3039,12 +3025,7 @@ func (s *DockerSuite) TestRunCapAddCHOWN(c *check.C) { func (s *DockerSuite) TestVolumeFromMixedRWOptions(c *check.C) { // TODO Windows post TP4. Enable the read-only bits once they are // supported on the platform. - prefix := "" - slash := `/` - if daemonPlatform == "windows" { - prefix = "c:" - slash = `\` - } + prefix, slash := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "run", "--name", "parent", "-v", prefix+"/test", "busybox", "true") if daemonPlatform != "windows" { @@ -3391,10 +3372,7 @@ func (s *DockerSuite) TestRunCreateContainerFailedCleanUp(c *check.C) { } func (s *DockerSuite) TestRunNamedVolume(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() testRequires(c, DaemonIsLinux) dockerCmd(c, "run", "--name=test", "-v", "testing:"+prefix+"/foo", "busybox", "sh", "-c", "echo hello > "+prefix+"/foo/bar") @@ -4147,10 +4125,7 @@ func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) { } func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "volume", "create", "--name", "test") @@ -4167,10 +4142,7 @@ func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) { } func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "volume", "create", "--name", "test") dockerCmd(c, "run", "--name=parent", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true") diff --git a/integration-cli/docker_cli_volume_test.go b/integration-cli/docker_cli_volume_test.go index 5a19ba539e..bd84becb66 100644 --- a/integration-cli/docker_cli_volume_test.go +++ b/integration-cli/docker_cli_volume_test.go @@ -64,10 +64,7 @@ func (s *DockerSuite) TestVolumeCliInspectMulti(c *check.C) { } func (s *DockerSuite) TestVolumeCliLs(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() out, _ := dockerCmd(c, "volume", "create") id := strings.TrimSpace(out) @@ -84,10 +81,7 @@ func (s *DockerSuite) TestVolumeCliLs(c *check.C) { } func (s *DockerSuite) TestVolumeCliLsFilterDangling(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() dockerCmd(c, "volume", "create", "--name", "testnotinuse1") dockerCmd(c, "volume", "create", "--name", "testisinuse1") dockerCmd(c, "volume", "create", "--name", "testisinuse2") @@ -144,10 +138,7 @@ func (s *DockerSuite) TestVolumeCliLsWithIncorrectFilterValue(c *check.C) { } func (s *DockerSuite) TestVolumeCliRm(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = "c:" - } + prefix, _ := getPrefixAndSlashFromDaemonPlatform() out, _ := dockerCmd(c, "volume", "create") id := strings.TrimSpace(out) diff --git a/integration-cli/utils.go b/integration-cli/utils.go index b24cce3f16..149f1c4540 100644 --- a/integration-cli/utils.go +++ b/integration-cli/utils.go @@ -9,6 +9,13 @@ import ( "github.com/docker/docker/pkg/integration" ) +func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) { + if daemonPlatform == "windows" { + return "c:", `\` + } + return "", "/" +} + func getExitCode(err error) (int, error) { return integration.GetExitCode(err) }