Explorar o código

Add unit test to cover changes.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Yong Tang %!s(int64=8) %!d(string=hai) anos
pai
achega
027297a60f
Modificáronse 2 ficheiros con 101 adicións e 16 borrados
  1. 101 0
      builder/dockerfile/copy_test.go
  2. 0 16
      integration-cli/docker_cli_build_test.go

+ 101 - 0
builder/dockerfile/copy_test.go

@@ -1,6 +1,7 @@
 package dockerfile
 package dockerfile
 
 
 import (
 import (
+	"net/http"
 	"testing"
 	"testing"
 
 
 	"github.com/gotestyourself/gotestyourself/fs"
 	"github.com/gotestyourself/gotestyourself/fs"
@@ -43,3 +44,103 @@ func TestIsExistingDirectory(t *testing.T) {
 		assert.Equal(t, testcase.expected, result, testcase.doc)
 		assert.Equal(t, testcase.expected, result, testcase.doc)
 	}
 	}
 }
 }
+
+func TestGetFilenameForDownload(t *testing.T) {
+	var testcases = []struct {
+		path        string
+		disposition string
+		expected    string
+	}{
+		{
+			path:     "http://www.example.com/",
+			expected: "",
+		},
+		{
+			path:     "http://www.example.com/xyz",
+			expected: "xyz",
+		},
+		{
+			path:     "http://www.example.com/xyz.html",
+			expected: "xyz.html",
+		},
+		{
+			path:     "http://www.example.com/xyz/",
+			expected: "",
+		},
+		{
+			path:     "http://www.example.com/xyz/uvw",
+			expected: "uvw",
+		},
+		{
+			path:     "http://www.example.com/xyz/uvw.html",
+			expected: "uvw.html",
+		},
+		{
+			path:     "http://www.example.com/xyz/uvw/",
+			expected: "",
+		},
+		{
+			path:     "/",
+			expected: "",
+		},
+		{
+			path:     "/xyz",
+			expected: "xyz",
+		},
+		{
+			path:     "/xyz.html",
+			expected: "xyz.html",
+		},
+		{
+			path:     "/xyz/",
+			expected: "",
+		},
+		{
+			path:        "/xyz/",
+			disposition: "attachment; filename=xyz.html",
+			expected:    "xyz.html",
+		},
+		{
+			disposition: "",
+			expected:    "",
+		},
+		{
+			disposition: "attachment; filename=xyz",
+			expected:    "xyz",
+		},
+		{
+			disposition: "attachment; filename=xyz.html",
+			expected:    "xyz.html",
+		},
+		{
+			disposition: "attachment; filename=\"xyz\"",
+			expected:    "xyz",
+		},
+		{
+			disposition: "attachment; filename=\"xyz.html\"",
+			expected:    "xyz.html",
+		},
+		{
+			disposition: "attachment; filename=\"/xyz.html\"",
+			expected:    "xyz.html",
+		},
+		{
+			disposition: "attachment; filename=\"/xyz/uvw\"",
+			expected:    "uvw",
+		},
+		{
+			disposition: "attachment; filename=\"Naïve file.txt\"",
+			expected:    "Naïve file.txt",
+		},
+	}
+	for _, testcase := range testcases {
+		resp := http.Response{
+			Header: make(map[string][]string),
+		}
+		if testcase.disposition != "" {
+			resp.Header.Add("Content-Disposition", testcase.disposition)
+		}
+		filename := getFilenameForDownload(testcase.path, &resp)
+		assert.Equal(t, testcase.expected, filename)
+	}
+}

+ 0 - 16
integration-cli/docker_cli_build_test.go

@@ -6506,19 +6506,3 @@ RUN touch /foop
 	c.Assert(err, check.IsNil)
 	c.Assert(err, check.IsNil)
 	c.Assert(d.String(), checker.Equals, getIDByName(c, name))
 	c.Assert(d.String(), checker.Equals, getIDByName(c, name))
 }
 }
-
-// Test case for #34208
-func (s *DockerSuite) TestBuildAddHTTPRoot(c *check.C) {
-	testRequires(c, Network, DaemonIsLinux)
-	buildImageSuccessfully(c, "buildaddhttproot", build.WithDockerfile(`
-                FROM scratch
-                ADD http://example.com/index.html /example1
-                ADD http://example.com /example2
-                ADD http://example.com /example3`))
-	buildImage("buildaddhttprootfailure", build.WithDockerfile(`
-                FROM scratch
-                ADD http://example.com/ /`)).Assert(c, icmd.Expected{
-		ExitCode: 1,
-		Err:      "cannot determine filename for source http://example.com/",
-	})
-}