diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index b6fc4a0768..5f94b35daa 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -25,10 +25,9 @@ import ( "github.com/docker/docker/integration-cli/cli/build/fakestorage" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/stringutils" - "github.com/docker/docker/pkg/testutil" icmd "github.com/docker/docker/pkg/testutil/cmd" "github.com/go-check/check" - "github.com/opencontainers/go-digest" + digest "github.com/opencontainers/go-digest" ) func (s *DockerSuite) TestBuildJSONEmptyRun(c *check.C) { diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go index 435411e528..8304d6eedb 100644 --- a/integration-cli/docker_cli_logs_test.go +++ b/integration-cli/docker_cli_logs_test.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/pkg/testutil" icmd "github.com/docker/docker/pkg/testutil/cmd" "github.com/go-check/check" ) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index fa2d7b31d9..8d18b7357a 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -28,7 +28,6 @@ import ( "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringutils" - "github.com/docker/docker/pkg/testutil" icmd "github.com/docker/docker/pkg/testutil/cmd" "github.com/docker/docker/runconfig" "github.com/docker/go-connections/nat" @@ -495,7 +494,7 @@ func (s *DockerSuite) TestRunVolumesFromInReadWriteMode(c *check.C) { func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) { testRequires(c, SameHostDaemon) prefix, slash := getPrefixAndSlashFromDaemonPlatform() - hostpath := testutil.RandomTmpDirPath("test", testEnv.DaemonPlatform()) + hostpath := RandomTmpDirPath("test", testEnv.DaemonPlatform()) if err := os.MkdirAll(hostpath, 0755); err != nil { c.Fatalf("Failed to create %s: %q", hostpath, err) } @@ -518,8 +517,8 @@ func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) { // Test for GH#10618 func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) { - path1 := testutil.RandomTmpDirPath("test1", testEnv.DaemonPlatform()) - path2 := testutil.RandomTmpDirPath("test2", testEnv.DaemonPlatform()) + path1 := RandomTmpDirPath("test1", testEnv.DaemonPlatform()) + path2 := RandomTmpDirPath("test2", testEnv.DaemonPlatform()) someplace := ":/someplace" if testEnv.DaemonPlatform() == "windows" { @@ -2183,7 +2182,7 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) { c.Fatalf("Data was copied on volumes-from but shouldn't be:\n%q", out) } - tmpDir := testutil.RandomTmpDirPath("docker_test_bind_mount_copy_data", testEnv.DaemonPlatform()) + tmpDir := RandomTmpDirPath("docker_test_bind_mount_copy_data", testEnv.DaemonPlatform()) if out, _, err := dockerCmdWithError("run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") { c.Fatalf("Data was copied on bind mount but shouldn't be:\n%q", out) } diff --git a/integration-cli/docker_deprecated_api_v124_test.go b/integration-cli/docker_deprecated_api_v124_test.go index 451fa50721..482425bf12 100644 --- a/integration-cli/docker_deprecated_api_v124_test.go +++ b/integration-cli/docker_deprecated_api_v124_test.go @@ -9,7 +9,6 @@ import ( "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/request" - "github.com/docker/docker/pkg/testutil" "github.com/go-check/check" ) @@ -45,7 +44,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - bindPath := testutil.RandomTmpDirPath("test", testEnv.DaemonPlatform()) + bindPath := RandomTmpDirPath("test", testEnv.DaemonPlatform()) config = map[string]interface{}{ "Binds": []string{bindPath + ":" + path}, } @@ -72,8 +71,8 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C) c.Assert(err, checker.IsNil) c.Assert(status, checker.Equals, http.StatusCreated) - bindPath1 := testutil.RandomTmpDirPath("test1", testEnv.DaemonPlatform()) - bindPath2 := testutil.RandomTmpDirPath("test2", testEnv.DaemonPlatform()) + bindPath1 := RandomTmpDirPath("test1", testEnv.DaemonPlatform()) + bindPath2 := RandomTmpDirPath("test2", testEnv.DaemonPlatform()) config = map[string]interface{}{ "Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"}, diff --git a/integration-cli/utils_test.go b/integration-cli/utils_test.go index 5eaf99e9d0..2497b4a39c 100644 --- a/integration-cli/utils_test.go +++ b/integration-cli/utils_test.go @@ -1,10 +1,13 @@ package main import ( + "fmt" + "os" "os/exec" - + "path/filepath" "strings" + "github.com/docker/docker/pkg/stringutils" "github.com/docker/docker/pkg/testutil/cmd" ) @@ -46,3 +49,18 @@ func ParseCgroupPaths(procCgroupData string) map[string]string { } return cgroupPaths } + +// RandomTmpDirPath provides a temporary path with rand string appended. +// does not create or checks if it exists. +func RandomTmpDirPath(s string, platform string) string { + // TODO: why doesn't this use os.TempDir() ? + tmp := "/tmp" + if platform == "windows" { + tmp = os.Getenv("TEMP") + } + path := filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10))) + if platform == "windows" { + return filepath.FromSlash(path) // Using \ + } + return filepath.ToSlash(path) // Using / +} diff --git a/pkg/testutil/utils.go b/pkg/testutil/utils.go index d694153265..f59ea54ab8 100644 --- a/pkg/testutil/utils.go +++ b/pkg/testutil/utils.go @@ -3,12 +3,9 @@ package testutil import ( "errors" "fmt" - "os" "os/exec" - "path/filepath" "strings" - "github.com/docker/docker/pkg/stringutils" "github.com/docker/docker/pkg/system" ) @@ -63,17 +60,3 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in // wait on last cmd return runCommandWithOutput(cmds[len(cmds)-1]) } - -// RandomTmpDirPath provides a temporary path with rand string appended. -// does not create or checks if it exists. -func RandomTmpDirPath(s string, platform string) string { - tmp := "/tmp" - if platform == "windows" { - tmp = os.Getenv("TEMP") - } - path := filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10))) - if platform == "windows" { - return filepath.FromSlash(path) // Using \ - } - return filepath.ToSlash(path) // Using / -} diff --git a/pkg/testutil/utils_test.go b/pkg/testutil/utils_test.go index b10ee31035..c475a6b9be 100644 --- a/pkg/testutil/utils_test.go +++ b/pkg/testutil/utils_test.go @@ -4,7 +4,6 @@ import ( "os" "os/exec" "runtime" - "strings" "testing" ) @@ -54,20 +53,3 @@ func TestRunCommandPipelineWithOutput(t *testing.T) { t.Fatalf("Expected %s for commands %v, got out:%s, exitCode:%d, err:%v", expectedOutput, cmds, out, exitCode, err) } } - -func TestRandomTmpDirPath(t *testing.T) { - path := RandomTmpDirPath("something", runtime.GOOS) - - prefix := "/tmp/something" - if runtime.GOOS == "windows" { - prefix = os.Getenv("TEMP") + `\something` - } - expectedSize := len(prefix) + 11 - - if !strings.HasPrefix(path, prefix) { - t.Fatalf("Expected generated path to have '%s' as prefix, got %s'", prefix, path) - } - if len(path) != expectedSize { - t.Fatalf("Expected generated path to be %d, got %d", expectedSize, len(path)) - } -}