This repository was archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmisc_test.go
More file actions
64 lines (61 loc) · 1.31 KB
/
misc_test.go
File metadata and controls
64 lines (61 loc) · 1.31 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package warplib
import (
"net/http"
"net/url"
"testing"
)
func Test_parseFileName(t *testing.T) {
type args struct {
req *http.Request
cd string
}
tests := []struct {
name string
args args
wantFn string
}{
{
name: "No Content Disposition",
args: args{
req: &http.Request{URL: &url.URL{Path: "hello/world.jpeg"}},
},
wantFn: "world.jpeg",
},
{
name: "Has Content Disposition",
args: args{
req: &http.Request{URL: &url.URL{Path: "hello/world.jpg"}},
cd: `attachment; filename="world.jpg"`,
},
wantFn: "world.jpg",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotFn := parseFileName(tt.args.req, tt.args.cd); gotFn != tt.wantFn {
t.Errorf("parseFileName() = %v, want %v", gotFn, tt.wantFn)
}
})
}
}
func TestGetPath(t *testing.T) {
type args struct {
directory string
file string
}
tests := []struct {
name string
args args
wantPath string
}{
{"case 1", args{".", "hello.bin"}, "./hello.bin"},
{"case 3", args{"home/bin/dir", "hello.bin"}, "home/bin/dir/hello.bin"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotPath := GetPath(tt.args.directory, tt.args.file); gotPath != tt.wantPath {
t.Errorf("GetPath() = %v, want %v", gotPath, tt.wantPath)
}
})
}
}