Browse code

Merge pull request #36241 from yongtang/02072018-create-tests

Migrate TestCreateTmpfsMountsTarget test to api test

Yong Tang authored on 2018/02/09 07:58:06
Showing 2 changed files
1 1
deleted file mode 100644
... ...
@@ -1,43 +0,0 @@
1
-// +build !windows
2
-
3
-package main
4
-
5
-import (
6
-	"strings"
7
-
8
-	"github.com/go-check/check"
9
-)
10
-
11
-// Test case for #30166 (target was not validated)
12
-func (s *DockerSuite) TestCreateTmpfsMountsTarget(c *check.C) {
13
-	testRequires(c, DaemonIsLinux)
14
-	type testCase struct {
15
-		target        string
16
-		expectedError string
17
-	}
18
-	cases := []testCase{
19
-		{
20
-			target:        ".",
21
-			expectedError: "mount path must be absolute",
22
-		},
23
-		{
24
-			target:        "foo",
25
-			expectedError: "mount path must be absolute",
26
-		},
27
-		{
28
-			target:        "/",
29
-			expectedError: "destination can't be '/'",
30
-		},
31
-		{
32
-			target:        "//",
33
-			expectedError: "destination can't be '/'",
34
-		},
35
-	}
36
-	for _, x := range cases {
37
-		out, _, _ := dockerCmdWithError("create", "--tmpfs", x.target, "busybox", "sh")
38
-		if x.expectedError != "" && !strings.Contains(out, x.expectedError) {
39
-			c.Fatalf("mounting tmpfs over %q should fail with %q, but got %q",
40
-				x.target, x.expectedError, out)
41
-		}
42
-	}
43
-}
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types/network"
10 10
 	"github.com/docker/docker/integration/util/request"
11 11
 	"github.com/docker/docker/internal/testutil"
12
+	"github.com/gotestyourself/gotestyourself/skip"
12 13
 )
13 14
 
14 15
 func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
... ...
@@ -91,3 +92,47 @@ func TestCreateWithInvalidEnv(t *testing.T) {
91 91
 		})
92 92
 	}
93 93
 }
94
+
95
+// Test case for #30166 (target was not validated)
96
+func TestCreateTmpfsMountsTarget(t *testing.T) {
97
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
98
+
99
+	defer setupTest(t)()
100
+	client := request.NewAPIClient(t)
101
+
102
+	testCases := []struct {
103
+		target        string
104
+		expectedError string
105
+	}{
106
+		{
107
+			target:        ".",
108
+			expectedError: "mount path must be absolute",
109
+		},
110
+		{
111
+			target:        "foo",
112
+			expectedError: "mount path must be absolute",
113
+		},
114
+		{
115
+			target:        "/",
116
+			expectedError: "destination can't be '/'",
117
+		},
118
+		{
119
+			target:        "//",
120
+			expectedError: "destination can't be '/'",
121
+		},
122
+	}
123
+
124
+	for _, tc := range testCases {
125
+		_, err := client.ContainerCreate(context.Background(),
126
+			&container.Config{
127
+				Image: "busybox",
128
+			},
129
+			&container.HostConfig{
130
+				Tmpfs: map[string]string{tc.target: ""},
131
+			},
132
+			&network.NetworkingConfig{},
133
+			"",
134
+		)
135
+		testutil.ErrorContains(t, err, tc.expectedError)
136
+	}
137
+}