-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
94 lines (89 loc) · 1.76 KB
/
request_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"net/http"
"net/url"
"testing"
)
func TestGeneratedURL(t *testing.T) {
tests := []struct {
name string
request *http.Request
expected string
}{
{
name: "blank request",
request: &http.Request{},
expected: "http://<nil>",
},
{
name: "no schema",
request: &http.Request{
URL: &url.URL{
Path: "/",
},
Host: "google.com",
},
expected: "http://google.com/",
},
{
name: "https",
request: &http.Request{
Header: http.Header{
"Scheme": []string{"https"},
},
URL: &url.URL{
Path: "/",
},
Host: "google.com",
},
expected: "https://google.com/",
},
}
for _, test := range tests {
if url := generateURL(test.request); url != test.expected {
t.Errorf("%s: expected URL `%s` doesn't match `%s`", test.name, test.expected, url)
}
}
}
func TestGeneratedCacheFilename(t *testing.T) {
tests := []struct {
name string
request *http.Request
expected string
}{
{
name: "blank request",
request: &http.Request{},
expected: "12898796920235164326",
},
{
name: "generic URL",
request: &http.Request{
URL: &url.URL{
Path: "/",
},
Host: "google.com",
},
expected: "3495272084109939400",
},
{
name: "steam client",
request: &http.Request{
Header: http.Header{
"User-Agent": []string{"Valve/Steam HTTP Client 1.0"},
},
URL: &url.URL{
Path: "/abc123",
},
Host: "google.com",
},
expected: "12349301149631723265",
},
}
for _, test := range tests {
url := generateURL(test.request)
if filename := generateCacheFilename(url, test.request); filename != test.expected {
t.Errorf("%s: expected filename `%s` doesn't match `%s`", test.name, test.expected, filename)
}
}
}