Skip to content

Commit 9db68f4

Browse files
committed
Remove RandomTmpDirPath
Signed-off-by: Daniel Nephin <dnephin@docker.com>
1 parent e8bd671 commit 9db68f4

File tree

7 files changed

+27
-48
lines changed

7 files changed

+27
-48
lines changed

integration-cli/docker_cli_build_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import (
2525
"github.com/docker/docker/integration-cli/cli/build/fakestorage"
2626
"github.com/docker/docker/pkg/archive"
2727
"github.com/docker/docker/pkg/stringutils"
28-
"github.com/docker/docker/pkg/testutil"
2928
icmd "github.com/docker/docker/pkg/testutil/cmd"
3029
"github.com/go-check/check"
31-
"github.com/opencontainers/go-digest"
30+
digest "github.com/opencontainers/go-digest"
3231
)
3332

3433
func (s *DockerSuite) TestBuildJSONEmptyRun(c *check.C) {

integration-cli/docker_cli_logs_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/docker/docker/integration-cli/checker"
1212
"github.com/docker/docker/integration-cli/cli"
1313
"github.com/docker/docker/pkg/jsonlog"
14-
"github.com/docker/docker/pkg/testutil"
1514
icmd "github.com/docker/docker/pkg/testutil/cmd"
1615
"github.com/go-check/check"
1716
)

integration-cli/docker_cli_run_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/docker/docker/pkg/mount"
2929
"github.com/docker/docker/pkg/stringid"
3030
"github.com/docker/docker/pkg/stringutils"
31-
"github.com/docker/docker/pkg/testutil"
3231
icmd "github.com/docker/docker/pkg/testutil/cmd"
3332
"github.com/docker/docker/runconfig"
3433
"github.com/docker/go-connections/nat"
@@ -495,7 +494,7 @@ func (s *DockerSuite) TestRunVolumesFromInReadWriteMode(c *check.C) {
495494
func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) {
496495
testRequires(c, SameHostDaemon)
497496
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
498-
hostpath := testutil.RandomTmpDirPath("test", testEnv.DaemonPlatform())
497+
hostpath := RandomTmpDirPath("test", testEnv.DaemonPlatform())
499498
if err := os.MkdirAll(hostpath, 0755); err != nil {
500499
c.Fatalf("Failed to create %s: %q", hostpath, err)
501500
}
@@ -518,8 +517,8 @@ func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) {
518517

519518
// Test for GH#10618
520519
func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) {
521-
path1 := testutil.RandomTmpDirPath("test1", testEnv.DaemonPlatform())
522-
path2 := testutil.RandomTmpDirPath("test2", testEnv.DaemonPlatform())
520+
path1 := RandomTmpDirPath("test1", testEnv.DaemonPlatform())
521+
path2 := RandomTmpDirPath("test2", testEnv.DaemonPlatform())
523522

524523
someplace := ":/someplace"
525524
if testEnv.DaemonPlatform() == "windows" {
@@ -2183,7 +2182,7 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) {
21832182
c.Fatalf("Data was copied on volumes-from but shouldn't be:\n%q", out)
21842183
}
21852184

2186-
tmpDir := testutil.RandomTmpDirPath("docker_test_bind_mount_copy_data", testEnv.DaemonPlatform())
2185+
tmpDir := RandomTmpDirPath("docker_test_bind_mount_copy_data", testEnv.DaemonPlatform())
21872186
if out, _, err := dockerCmdWithError("run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") {
21882187
c.Fatalf("Data was copied on bind mount but shouldn't be:\n%q", out)
21892188
}

integration-cli/docker_deprecated_api_v124_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/docker/docker/integration-cli/checker"
1111
"github.com/docker/docker/integration-cli/request"
12-
"github.com/docker/docker/pkg/testutil"
1312
"github.com/go-check/check"
1413
)
1514

@@ -45,7 +44,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) {
4544
c.Assert(err, checker.IsNil)
4645
c.Assert(status, checker.Equals, http.StatusCreated)
4746

48-
bindPath := testutil.RandomTmpDirPath("test", testEnv.DaemonPlatform())
47+
bindPath := RandomTmpDirPath("test", testEnv.DaemonPlatform())
4948
config = map[string]interface{}{
5049
"Binds": []string{bindPath + ":" + path},
5150
}
@@ -72,8 +71,8 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C)
7271
c.Assert(err, checker.IsNil)
7372
c.Assert(status, checker.Equals, http.StatusCreated)
7473

75-
bindPath1 := testutil.RandomTmpDirPath("test1", testEnv.DaemonPlatform())
76-
bindPath2 := testutil.RandomTmpDirPath("test2", testEnv.DaemonPlatform())
74+
bindPath1 := RandomTmpDirPath("test1", testEnv.DaemonPlatform())
75+
bindPath2 := RandomTmpDirPath("test2", testEnv.DaemonPlatform())
7776

7877
config = map[string]interface{}{
7978
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},

integration-cli/utils_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package main
22

33
import (
4+
"fmt"
5+
"os"
46
"os/exec"
5-
7+
"path/filepath"
68
"strings"
79

10+
"github.com/docker/docker/pkg/stringutils"
811
"github.com/docker/docker/pkg/testutil/cmd"
912
)
1013

@@ -46,3 +49,18 @@ func ParseCgroupPaths(procCgroupData string) map[string]string {
4649
}
4750
return cgroupPaths
4851
}
52+
53+
// RandomTmpDirPath provides a temporary path with rand string appended.
54+
// does not create or checks if it exists.
55+
func RandomTmpDirPath(s string, platform string) string {
56+
// TODO: why doesn't this use os.TempDir() ?
57+
tmp := "/tmp"
58+
if platform == "windows" {
59+
tmp = os.Getenv("TEMP")
60+
}
61+
path := filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10)))
62+
if platform == "windows" {
63+
return filepath.FromSlash(path) // Using \
64+
}
65+
return filepath.ToSlash(path) // Using /
66+
}

pkg/testutil/utils.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ package testutil
33
import (
44
"errors"
55
"fmt"
6-
"os"
76
"os/exec"
8-
"path/filepath"
97
"strings"
108

11-
"github.com/docker/docker/pkg/stringutils"
129
"github.com/docker/docker/pkg/system"
1310
)
1411

@@ -63,17 +60,3 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in
6360
// wait on last cmd
6461
return runCommandWithOutput(cmds[len(cmds)-1])
6562
}
66-
67-
// RandomTmpDirPath provides a temporary path with rand string appended.
68-
// does not create or checks if it exists.
69-
func RandomTmpDirPath(s string, platform string) string {
70-
tmp := "/tmp"
71-
if platform == "windows" {
72-
tmp = os.Getenv("TEMP")
73-
}
74-
path := filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10)))
75-
if platform == "windows" {
76-
return filepath.FromSlash(path) // Using \
77-
}
78-
return filepath.ToSlash(path) // Using /
79-
}

pkg/testutil/utils_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"os"
55
"os/exec"
66
"runtime"
7-
"strings"
87
"testing"
98
)
109

@@ -54,20 +53,3 @@ func TestRunCommandPipelineWithOutput(t *testing.T) {
5453
t.Fatalf("Expected %s for commands %v, got out:%s, exitCode:%d, err:%v", expectedOutput, cmds, out, exitCode, err)
5554
}
5655
}
57-
58-
func TestRandomTmpDirPath(t *testing.T) {
59-
path := RandomTmpDirPath("something", runtime.GOOS)
60-
61-
prefix := "/tmp/something"
62-
if runtime.GOOS == "windows" {
63-
prefix = os.Getenv("TEMP") + `\something`
64-
}
65-
expectedSize := len(prefix) + 11
66-
67-
if !strings.HasPrefix(path, prefix) {
68-
t.Fatalf("Expected generated path to have '%s' as prefix, got %s'", prefix, path)
69-
}
70-
if len(path) != expectedSize {
71-
t.Fatalf("Expected generated path to be %d, got %d", expectedSize, len(path))
72-
}
73-
}

0 commit comments

Comments
 (0)