-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize_url_test.go
52 lines (49 loc) · 1.04 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
48
49
50
51
52
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 www",
inputURL: "https://www.boot.dev/path",
expected: "boot.dev/path",
},
{
name: "http scheme",
inputURL: "http://blog.boot.dev/path",
expected: "blog.boot.dev/path",
},
{
name: "no scheme",
inputURL: "blog.boot.dev/path",
expected: "blog.boot.dev/path",
},
{
name: "root path",
inputURL: "https://www.boot.dev/",
expected: "boot.dev/",
},
}
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)
}
})
}
}