Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin authored on 2017/08/23 05:08:42... | ... |
@@ -25,10 +25,9 @@ import ( |
25 | 25 |
"github.com/docker/docker/integration-cli/cli/build/fakestorage" |
26 | 26 |
"github.com/docker/docker/pkg/archive" |
27 | 27 |
"github.com/docker/docker/pkg/stringutils" |
28 |
- "github.com/docker/docker/pkg/testutil" |
|
29 | 28 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
30 | 29 |
"github.com/go-check/check" |
31 |
- "github.com/opencontainers/go-digest" |
|
30 |
+ digest "github.com/opencontainers/go-digest" |
|
32 | 31 |
) |
33 | 32 |
|
34 | 33 |
func (s *DockerSuite) TestBuildJSONEmptyRun(c *check.C) { |
... | ... |
@@ -11,7 +11,6 @@ import ( |
11 | 11 |
"github.com/docker/docker/integration-cli/checker" |
12 | 12 |
"github.com/docker/docker/integration-cli/cli" |
13 | 13 |
"github.com/docker/docker/pkg/jsonlog" |
14 |
- "github.com/docker/docker/pkg/testutil" |
|
15 | 14 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
16 | 15 |
"github.com/go-check/check" |
17 | 16 |
) |
... | ... |
@@ -28,7 +28,6 @@ import ( |
28 | 28 |
"github.com/docker/docker/pkg/mount" |
29 | 29 |
"github.com/docker/docker/pkg/stringid" |
30 | 30 |
"github.com/docker/docker/pkg/stringutils" |
31 |
- "github.com/docker/docker/pkg/testutil" |
|
32 | 31 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
33 | 32 |
"github.com/docker/docker/runconfig" |
34 | 33 |
"github.com/docker/go-connections/nat" |
... | ... |
@@ -495,7 +494,7 @@ func (s *DockerSuite) TestRunVolumesFromInReadWriteMode(c *check.C) { |
495 | 495 |
func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) { |
496 | 496 |
testRequires(c, SameHostDaemon) |
497 | 497 |
prefix, slash := getPrefixAndSlashFromDaemonPlatform() |
498 |
- hostpath := testutil.RandomTmpDirPath("test", testEnv.DaemonPlatform()) |
|
498 |
+ hostpath := RandomTmpDirPath("test", testEnv.DaemonPlatform()) |
|
499 | 499 |
if err := os.MkdirAll(hostpath, 0755); err != nil { |
500 | 500 |
c.Fatalf("Failed to create %s: %q", hostpath, err) |
501 | 501 |
} |
... | ... |
@@ -518,8 +517,8 @@ func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) { |
518 | 518 |
|
519 | 519 |
// Test for GH#10618 |
520 | 520 |
func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) { |
521 |
- path1 := testutil.RandomTmpDirPath("test1", testEnv.DaemonPlatform()) |
|
522 |
- path2 := testutil.RandomTmpDirPath("test2", testEnv.DaemonPlatform()) |
|
521 |
+ path1 := RandomTmpDirPath("test1", testEnv.DaemonPlatform()) |
|
522 |
+ path2 := RandomTmpDirPath("test2", testEnv.DaemonPlatform()) |
|
523 | 523 |
|
524 | 524 |
someplace := ":/someplace" |
525 | 525 |
if testEnv.DaemonPlatform() == "windows" { |
... | ... |
@@ -2183,7 +2182,7 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) { |
2183 | 2183 |
c.Fatalf("Data was copied on volumes-from but shouldn't be:\n%q", out) |
2184 | 2184 |
} |
2185 | 2185 |
|
2186 |
- tmpDir := testutil.RandomTmpDirPath("docker_test_bind_mount_copy_data", testEnv.DaemonPlatform()) |
|
2186 |
+ tmpDir := RandomTmpDirPath("docker_test_bind_mount_copy_data", testEnv.DaemonPlatform()) |
|
2187 | 2187 |
if out, _, err := dockerCmdWithError("run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") { |
2188 | 2188 |
c.Fatalf("Data was copied on bind mount but shouldn't be:\n%q", out) |
2189 | 2189 |
} |
... | ... |
@@ -9,7 +9,6 @@ import ( |
9 | 9 |
|
10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
11 | 11 |
"github.com/docker/docker/integration-cli/request" |
12 |
- "github.com/docker/docker/pkg/testutil" |
|
13 | 12 |
"github.com/go-check/check" |
14 | 13 |
) |
15 | 14 |
|
... | ... |
@@ -45,7 +44,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) { |
45 | 45 |
c.Assert(err, checker.IsNil) |
46 | 46 |
c.Assert(status, checker.Equals, http.StatusCreated) |
47 | 47 |
|
48 |
- bindPath := testutil.RandomTmpDirPath("test", testEnv.DaemonPlatform()) |
|
48 |
+ bindPath := RandomTmpDirPath("test", testEnv.DaemonPlatform()) |
|
49 | 49 |
config = map[string]interface{}{ |
50 | 50 |
"Binds": []string{bindPath + ":" + path}, |
51 | 51 |
} |
... | ... |
@@ -72,8 +71,8 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C) |
72 | 72 |
c.Assert(err, checker.IsNil) |
73 | 73 |
c.Assert(status, checker.Equals, http.StatusCreated) |
74 | 74 |
|
75 |
- bindPath1 := testutil.RandomTmpDirPath("test1", testEnv.DaemonPlatform()) |
|
76 |
- bindPath2 := testutil.RandomTmpDirPath("test2", testEnv.DaemonPlatform()) |
|
75 |
+ bindPath1 := RandomTmpDirPath("test1", testEnv.DaemonPlatform()) |
|
76 |
+ bindPath2 := RandomTmpDirPath("test2", testEnv.DaemonPlatform()) |
|
77 | 77 |
|
78 | 78 |
config = map[string]interface{}{ |
79 | 79 |
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"}, |
... | ... |
@@ -1,10 +1,13 @@ |
1 | 1 |
package main |
2 | 2 |
|
3 | 3 |
import ( |
4 |
+ "fmt" |
|
5 |
+ "os" |
|
4 | 6 |
"os/exec" |
5 |
- |
|
7 |
+ "path/filepath" |
|
6 | 8 |
"strings" |
7 | 9 |
|
10 |
+ "github.com/docker/docker/pkg/stringutils" |
|
8 | 11 |
"github.com/docker/docker/pkg/testutil/cmd" |
9 | 12 |
) |
10 | 13 |
|
... | ... |
@@ -46,3 +49,18 @@ func ParseCgroupPaths(procCgroupData string) map[string]string { |
46 | 46 |
} |
47 | 47 |
return cgroupPaths |
48 | 48 |
} |
49 |
+ |
|
50 |
+// RandomTmpDirPath provides a temporary path with rand string appended. |
|
51 |
+// does not create or checks if it exists. |
|
52 |
+func RandomTmpDirPath(s string, platform string) string { |
|
53 |
+ // TODO: why doesn't this use os.TempDir() ? |
|
54 |
+ tmp := "/tmp" |
|
55 |
+ if platform == "windows" { |
|
56 |
+ tmp = os.Getenv("TEMP") |
|
57 |
+ } |
|
58 |
+ path := filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10))) |
|
59 |
+ if platform == "windows" { |
|
60 |
+ return filepath.FromSlash(path) // Using \ |
|
61 |
+ } |
|
62 |
+ return filepath.ToSlash(path) // Using / |
|
63 |
+} |
... | ... |
@@ -3,12 +3,9 @@ package testutil |
3 | 3 |
import ( |
4 | 4 |
"errors" |
5 | 5 |
"fmt" |
6 |
- "os" |
|
7 | 6 |
"os/exec" |
8 |
- "path/filepath" |
|
9 | 7 |
"strings" |
10 | 8 |
|
11 |
- "github.com/docker/docker/pkg/stringutils" |
|
12 | 9 |
"github.com/docker/docker/pkg/system" |
13 | 10 |
) |
14 | 11 |
|
... | ... |
@@ -63,17 +60,3 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in |
63 | 63 |
// wait on last cmd |
64 | 64 |
return runCommandWithOutput(cmds[len(cmds)-1]) |
65 | 65 |
} |
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 |
-} |
... | ... |
@@ -4,7 +4,6 @@ import ( |
4 | 4 |
"os" |
5 | 5 |
"os/exec" |
6 | 6 |
"runtime" |
7 |
- "strings" |
|
8 | 7 |
"testing" |
9 | 8 |
) |
10 | 9 |
|
... | ... |
@@ -54,20 +53,3 @@ func TestRunCommandPipelineWithOutput(t *testing.T) { |
54 | 54 |
t.Fatalf("Expected %s for commands %v, got out:%s, exitCode:%d, err:%v", expectedOutput, cmds, out, exitCode, err) |
55 | 55 |
} |
56 | 56 |
} |
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 |
-} |