-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize_url_test.go
47 lines (42 loc) · 1.01 KB
/
normalize_url_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
package main
import "testing"
func TestNormalizeURL(t *testing.T) {
tests := []struct {
name string
inputURL string
expected string
}{
{
name: "remove scheme",
inputURL: "https://blog.boot.dev/path",
expected: "blog.boot.dev/path",
},
{
name: "remove trailing slash",
inputURL: "https://blog.boot.dev/path/",
expected: "blog.boot.dev/path",
},
{
name: "lowercase capital letters",
inputURL: "https://BLOG.boot.dev/PATH",
expected: "blog.boot.dev/path",
},
{
name: "remove scheme and capitals and trailing slash",
inputURL: "http://BLOG.boot.dev/path/",
expected: "blog.boot.dev/path",
},
}
for i, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
actual, err := normalizeURL(tc.inputURL)
if err != nil {
t.Errorf("Test %v - '%s' FAIL: unexpected error: %v", i, tc.name, err)
return
}
if actual != tc.expected {
t.Errorf("Test %v - %s FAIL: expected URL: %v, actual: %v", i, tc.name, tc.expected, actual)
}
})
}
}