1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add unit test to cover changes.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2017-08-15 00:33:31 +00:00
parent bea0a072d8
commit 027297a60f
2 changed files with 101 additions and 16 deletions

View file

@ -1,6 +1,7 @@
package dockerfile
import (
"net/http"
"testing"
"github.com/gotestyourself/gotestyourself/fs"
@ -43,3 +44,103 @@ func TestIsExistingDirectory(t *testing.T) {
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)
}
}

View file

@ -6506,19 +6506,3 @@ RUN touch /foop
c.Assert(err, check.IsNil)
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/",
})
}