浏览代码

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

Migrate TestCreateTmpfsMountsTarget test to api test
Yong Tang 7 年之前
父节点
当前提交
15001f83bd
共有 2 个文件被更改,包括 45 次插入43 次删除
  1. 0 43
      integration-cli/docker_cli_create_unix_test.go
  2. 45 0
      integration/container/create_test.go

+ 0 - 43
integration-cli/docker_cli_create_unix_test.go

@@ -1,43 +0,0 @@
-// +build !windows
-
-package main
-
-import (
-	"strings"
-
-	"github.com/go-check/check"
-)
-
-// Test case for #30166 (target was not validated)
-func (s *DockerSuite) TestCreateTmpfsMountsTarget(c *check.C) {
-	testRequires(c, DaemonIsLinux)
-	type testCase struct {
-		target        string
-		expectedError string
-	}
-	cases := []testCase{
-		{
-			target:        ".",
-			expectedError: "mount path must be absolute",
-		},
-		{
-			target:        "foo",
-			expectedError: "mount path must be absolute",
-		},
-		{
-			target:        "/",
-			expectedError: "destination can't be '/'",
-		},
-		{
-			target:        "//",
-			expectedError: "destination can't be '/'",
-		},
-	}
-	for _, x := range cases {
-		out, _, _ := dockerCmdWithError("create", "--tmpfs", x.target, "busybox", "sh")
-		if x.expectedError != "" && !strings.Contains(out, x.expectedError) {
-			c.Fatalf("mounting tmpfs over %q should fail with %q, but got %q",
-				x.target, x.expectedError, out)
-		}
-	}
-}

+ 45 - 0
integration/container/create_test.go

@@ -9,6 +9,7 @@ import (
 	"github.com/docker/docker/api/types/network"
 	"github.com/docker/docker/integration/util/request"
 	"github.com/docker/docker/internal/testutil"
+	"github.com/gotestyourself/gotestyourself/skip"
 )
 
 func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
@@ -91,3 +92,47 @@ func TestCreateWithInvalidEnv(t *testing.T) {
 		})
 	}
 }
+
+// Test case for #30166 (target was not validated)
+func TestCreateTmpfsMountsTarget(t *testing.T) {
+	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
+
+	defer setupTest(t)()
+	client := request.NewAPIClient(t)
+
+	testCases := []struct {
+		target        string
+		expectedError string
+	}{
+		{
+			target:        ".",
+			expectedError: "mount path must be absolute",
+		},
+		{
+			target:        "foo",
+			expectedError: "mount path must be absolute",
+		},
+		{
+			target:        "/",
+			expectedError: "destination can't be '/'",
+		},
+		{
+			target:        "//",
+			expectedError: "destination can't be '/'",
+		},
+	}
+
+	for _, tc := range testCases {
+		_, err := client.ContainerCreate(context.Background(),
+			&container.Config{
+				Image: "busybox",
+			},
+			&container.HostConfig{
+				Tmpfs: map[string]string{tc.target: ""},
+			},
+			&network.NetworkingConfig{},
+			"",
+		)
+		testutil.ErrorContains(t, err, tc.expectedError)
+	}
+}