forked from melbahja/got
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilename_test.go
40 lines (35 loc) · 1.54 KB
/
filename_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package got
import (
"testing"
)
var TestUrls = map[string]string{
"http://example.com/some/path/video.mp4?hash=deadbeef&expires=123456789": "video.mp4",
"http://example.com/some/path/video.mp4": "video.mp4",
"http://example.com/index.html": "index.html",
"http://example.com/": "got.output",
"http://example.com/?page=about": "got.output",
"http://example.com/some/path/": "got.output",
"http://example.com/some/path/?page=about": "got.output",
"http://example.com/about.php?session=asdf": "about.php",
}
var TestHeaderValues = map[string]string{
`attachment`: "",
`attachment; filename="filename.jpg"`: "filename.jpg",
`attachment; filename="../filename.jpg"`: "",
`attachment; filename="../../../etc/passwd"`: "",
`attachment; name="test"; filename="go.mp4"`: "go.mp4",
}
func TestGetFilename(t *testing.T) {
for url, expected := range TestUrls {
if result := GetFilename(url); result != expected {
t.Errorf("Expected name '%s' from url '%s', but got '%s'", expected, url, result)
}
}
}
func TestGetDefaultFileNameFromHeader(t *testing.T) {
for url, expected := range TestHeaderValues {
if result := getNameFromHeader(url); result != expected {
t.Errorf("Expected name '%s' from url '%s', but got '%s'", expected, url, result)
}
}
}