-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
60 lines (56 loc) · 1.14 KB
/
utils_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
package simular
import (
"testing"
)
func TestNormalizeURL(t *testing.T) {
testcases := []struct {
inputs []string
expected string
expectedErr bool
}{
{
[]string{
"www.example.com",
"www.example.com:80",
"http://www.example.com",
"HTTP://WWW.eXamPle.Com:80",
},
"http://www.example.com",
false,
},
{
[]string{
"http://www.example.com/a/b/index.html?foo=val&bar=val#t=20",
"www.example.com:80/a/b///../x/../../index.html?foo=val&bar=val#t=20",
},
"http://www.example.com/a/b/index.html?bar=val&foo=val#t=20",
false,
},
{
[]string{
"<funnytag>",
"javascript:evilFunc()",
"anotherscheme:garbage",
},
"",
true,
},
}
for _, testcase := range testcases {
for _, input := range testcase.inputs {
got, err := normalizeURL(input)
if testcase.expectedErr {
if err == nil {
t.Errorf("Expected error for '%s', got none", input)
}
} else {
if err != nil {
t.Errorf("Unexpected error, got %#v", err)
}
if got != testcase.expected {
t.Errorf("Unexepcted output, expected: %s, got %s", testcase.expected, got)
}
}
}
}
}