|
@@ -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)
|
|
|
|
+ }
|
|
|
|
+}
|