Browse code

Migrate TestCreateTmpfsMountsTarget test to api test

This fix migrates TestCreateTmpfsMountsTarget test to api test,
and removed integration-cli/docker_cli_create_unix_test.go

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2018/02/08 09:21:44
Showing 1 changed files
... ...
@@ -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
+}