Browse code

Add a getPrefixAndSlashFromDaemonPlatform …

… to limit code duplication in integration tests :P

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/02/03 23:16:00
Showing 6 changed files
... ...
@@ -11,10 +11,7 @@ import (
11 11
 )
12 12
 
13 13
 func (s *DockerSuite) TestVolumesApiList(c *check.C) {
14
-	prefix := ""
15
-	if daemonPlatform == "windows" {
16
-		prefix = "c:"
17
-	}
14
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
18 15
 	dockerCmd(c, "run", "-d", "-v", prefix+"/foo", "busybox")
19 16
 
20 17
 	status, b, err := sockRequest("GET", "/volumes", nil)
... ...
@@ -43,10 +40,7 @@ func (s *DockerSuite) TestVolumesApiCreate(c *check.C) {
43 43
 }
44 44
 
45 45
 func (s *DockerSuite) TestVolumesApiRemove(c *check.C) {
46
-	prefix := ""
47
-	if daemonPlatform == "windows" {
48
-		prefix = "c:"
49
-	}
46
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
50 47
 	dockerCmd(c, "run", "-d", "-v", prefix+"/foo", "--name=test", "busybox")
51 48
 
52 49
 	status, b, err := sockRequest("GET", "/volumes", nil)
... ...
@@ -429,12 +429,8 @@ func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) {
429 429
 		c.Skip("Fails on Windows CI")
430 430
 	}
431 431
 	name := "foo"
432
-	slash := "/"
433
-	prefix := ""
434
-	if daemonPlatform == "windows" {
435
-		prefix = "c:"
436
-		slash = `/`
437
-	}
432
+
433
+	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
438 434
 	dir := prefix + slash + "home" + slash + "foo" + slash + "bar"
439 435
 
440 436
 	dockerCmd(c, "create", "--name", name, "-w", dir, "busybox")
... ...
@@ -12,12 +12,7 @@ import (
12 12
 func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
13 13
 	testRequires(c, SameHostDaemon)
14 14
 
15
-	prefix := ""
16
-	slash := "/"
17
-	if daemonPlatform == "windows" {
18
-		prefix = "c:"
19
-		slash = `\`
20
-	}
15
+	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
21 16
 
22 17
 	tempDir, err := ioutil.TempDir("", "test-rm-container-with-removed-volume-")
23 18
 	if err != nil {
... ...
@@ -34,12 +29,7 @@ func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
34 34
 }
35 35
 
36 36
 func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) {
37
-	prefix := ""
38
-	slash := "/"
39
-	if daemonPlatform == "windows" {
40
-		prefix = "c:"
41
-		slash = `\`
42
-	}
37
+	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
43 38
 
44 39
 	dockerCmd(c, "run", "--name", "foo", "-v", prefix+slash+"srv", "busybox", "true")
45 40
 
... ...
@@ -2102,10 +2102,7 @@ func (s *DockerSuite) TestRunAllocatePortInReservedRange(c *check.C) {
2102 2102
 func (s *DockerSuite) TestRunMountOrdering(c *check.C) {
2103 2103
 	// TODO Windows: Post TP4. Updated, but Windows does not support nested mounts currently.
2104 2104
 	testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace)
2105
-	prefix := ""
2106
-	if daemonPlatform == "windows" {
2107
-		prefix = "c:"
2108
-	}
2105
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
2109 2106
 
2110 2107
 	tmpDir, err := ioutil.TempDir("", "docker_nested_mount_test")
2111 2108
 	if err != nil {
... ...
@@ -2150,10 +2147,7 @@ func (s *DockerSuite) TestRunMountOrdering(c *check.C) {
2150 2150
 func (s *DockerSuite) TestRunReuseBindVolumeThatIsSymlink(c *check.C) {
2151 2151
 	// Not applicable on Windows as Windows does not support volumes
2152 2152
 	testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace)
2153
-	prefix := ""
2154
-	if daemonPlatform == "windows" {
2155
-		prefix = "c:"
2156
-	}
2153
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
2157 2154
 
2158 2155
 	tmpDir, err := ioutil.TempDir(os.TempDir(), "testlink")
2159 2156
 	if err != nil {
... ...
@@ -2236,12 +2230,7 @@ func (s *DockerSuite) TestRunNoOutputFromPullInStdout(c *check.C) {
2236 2236
 
2237 2237
 func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) {
2238 2238
 	testRequires(c, SameHostDaemon)
2239
-	prefix := ""
2240
-	slash := `/`
2241
-	if daemonPlatform == "windows" {
2242
-		prefix = "c:"
2243
-		slash = `\`
2244
-	}
2239
+	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
2245 2240
 	if _, err := buildImage("run_volumes_clean_paths",
2246 2241
 		`FROM busybox
2247 2242
 		VOLUME `+prefix+`/foo/`,
... ...
@@ -2802,10 +2791,7 @@ func (s *DockerSuite) TestRunContainerWithReadonlyRootfsWithAddHostFlag(c *check
2802 2802
 }
2803 2803
 
2804 2804
 func (s *DockerSuite) TestRunVolumesFromRestartAfterRemoved(c *check.C) {
2805
-	prefix := ""
2806
-	if daemonPlatform == "windows" {
2807
-		prefix = "c:"
2808
-	}
2805
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
2809 2806
 	dockerCmd(c, "run", "-d", "--name", "voltest", "-v", prefix+"/foo", "busybox", "sleep", "60")
2810 2807
 	dockerCmd(c, "run", "-d", "--name", "restarter", "--volumes-from", "voltest", "busybox", "sleep", "60")
2811 2808
 
... ...
@@ -3039,12 +3025,7 @@ func (s *DockerSuite) TestRunCapAddCHOWN(c *check.C) {
3039 3039
 func (s *DockerSuite) TestVolumeFromMixedRWOptions(c *check.C) {
3040 3040
 	// TODO Windows post TP4. Enable the read-only bits once they are
3041 3041
 	// supported on the platform.
3042
-	prefix := ""
3043
-	slash := `/`
3044
-	if daemonPlatform == "windows" {
3045
-		prefix = "c:"
3046
-		slash = `\`
3047
-	}
3042
+	prefix, slash := getPrefixAndSlashFromDaemonPlatform()
3048 3043
 
3049 3044
 	dockerCmd(c, "run", "--name", "parent", "-v", prefix+"/test", "busybox", "true")
3050 3045
 	if daemonPlatform != "windows" {
... ...
@@ -3391,10 +3372,7 @@ func (s *DockerSuite) TestRunCreateContainerFailedCleanUp(c *check.C) {
3391 3391
 }
3392 3392
 
3393 3393
 func (s *DockerSuite) TestRunNamedVolume(c *check.C) {
3394
-	prefix := ""
3395
-	if daemonPlatform == "windows" {
3396
-		prefix = "c:"
3397
-	}
3394
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
3398 3395
 	testRequires(c, DaemonIsLinux)
3399 3396
 	dockerCmd(c, "run", "--name=test", "-v", "testing:"+prefix+"/foo", "busybox", "sh", "-c", "echo hello > "+prefix+"/foo/bar")
3400 3397
 
... ...
@@ -4147,10 +4125,7 @@ func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) {
4147 4147
 }
4148 4148
 
4149 4149
 func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) {
4150
-	prefix := ""
4151
-	if daemonPlatform == "windows" {
4152
-		prefix = "c:"
4153
-	}
4150
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
4154 4151
 
4155 4152
 	dockerCmd(c, "volume", "create", "--name", "test")
4156 4153
 
... ...
@@ -4167,10 +4142,7 @@ func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) {
4167 4167
 }
4168 4168
 
4169 4169
 func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) {
4170
-	prefix := ""
4171
-	if daemonPlatform == "windows" {
4172
-		prefix = "c:"
4173
-	}
4170
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
4174 4171
 
4175 4172
 	dockerCmd(c, "volume", "create", "--name", "test")
4176 4173
 	dockerCmd(c, "run", "--name=parent", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true")
... ...
@@ -64,10 +64,7 @@ func (s *DockerSuite) TestVolumeCliInspectMulti(c *check.C) {
64 64
 }
65 65
 
66 66
 func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
67
-	prefix := ""
68
-	if daemonPlatform == "windows" {
69
-		prefix = "c:"
70
-	}
67
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
71 68
 	out, _ := dockerCmd(c, "volume", "create")
72 69
 	id := strings.TrimSpace(out)
73 70
 
... ...
@@ -84,10 +81,7 @@ func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
84 84
 }
85 85
 
86 86
 func (s *DockerSuite) TestVolumeCliLsFilterDangling(c *check.C) {
87
-	prefix := ""
88
-	if daemonPlatform == "windows" {
89
-		prefix = "c:"
90
-	}
87
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
91 88
 	dockerCmd(c, "volume", "create", "--name", "testnotinuse1")
92 89
 	dockerCmd(c, "volume", "create", "--name", "testisinuse1")
93 90
 	dockerCmd(c, "volume", "create", "--name", "testisinuse2")
... ...
@@ -144,10 +138,7 @@ func (s *DockerSuite) TestVolumeCliLsWithIncorrectFilterValue(c *check.C) {
144 144
 }
145 145
 
146 146
 func (s *DockerSuite) TestVolumeCliRm(c *check.C) {
147
-	prefix := ""
148
-	if daemonPlatform == "windows" {
149
-		prefix = "c:"
150
-	}
147
+	prefix, _ := getPrefixAndSlashFromDaemonPlatform()
151 148
 	out, _ := dockerCmd(c, "volume", "create")
152 149
 	id := strings.TrimSpace(out)
153 150
 
... ...
@@ -9,6 +9,13 @@ import (
9 9
 	"github.com/docker/docker/pkg/integration"
10 10
 )
11 11
 
12
+func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {
13
+	if daemonPlatform == "windows" {
14
+		return "c:", `\`
15
+	}
16
+	return "", "/"
17
+}
18
+
12 19
 func getExitCode(err error) (int, error) {
13 20
 	return integration.GetExitCode(err)
14 21
 }