-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_test.go
More file actions
86 lines (73 loc) · 1.67 KB
/
Copy pathhttp_test.go
File metadata and controls
86 lines (73 loc) · 1.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package util
import
// the package url
(
"strings"
"testing"
)
func TestHostCore(t *testing.T) {
type tcT struct {
inp string
want1 string
want2 []string
}
tcs := []tcT{
{"sd1.sd2.sd3.zew.de:332",
"zew.de",
[]string{"sd1", "sd2", "sd3"},
},
{"www.zew.de:332",
"zew.de",
[]string{},
},
{"sd1.www.zew.de:332",
"zew.de",
[]string{"sd1"},
},
{"subdom1.faz.net",
"faz.net",
[]string{"subdom1"},
},
{"faz.net",
"faz.net",
[]string{},
},
{"net",
"net",
[]string{},
},
}
for i, tc := range tcs {
got1, gots2 := HostCore(tc.inp)
got2 := strings.Join(gots2, "")
want2 := strings.Join(tc.want2, "")
if got1 != tc.want1 || got2 != want2 {
t.Errorf("%2v: \ninp %-20v \nwant1-2 %-20v %-20v \ngot1-2 %-20v %-20v\n", i, tc.inp, tc.want1, want2, got1, got2)
}
}
}
func TestNormalizeSubdomainsToPath(t *testing.T) {
type tcT struct {
inp string
want string
}
tcs := []tcT{
{"http://iche:secret@sd1.sd2.sd3.zew.de:332/dir1/dir2/file.ext?p1=v1#aaa",
"zew.de/sd1/sd2/sd3/dir1/dir2/file.ext?p1=v1#aaa"},
{"www.zew.de:332/dir1/dir2/file.ext?p1=v1#aaa",
"zew.de/dir1/dir2/file.ext?p1=v1#aaa"},
{"www.subd1.zew.de:33332/dir1/dir2/file.ext?p1=v1#aaa",
"zew.de/www/subd1/dir1/dir2/file.ext?p1=v1#aaa"},
{"subdom1.faz.net/aktuell/second.html",
"faz.net/subdom1/aktuell/second.html"},
}
for i, tc := range tcs {
u, err := UrlParseImproved(tc.inp)
CheckErr(err)
got := NormalizeSubdomainsToPath(u)
t.Logf("%2v: \ninp %-20v - \nwant %-20v \ngot %-20v\n", i, tc.inp, tc.want, got)
if got != tc.want {
t.Errorf("%2v: \ninp %-20v - \nwant %-20v \ngot %-20v\n", i, tc.inp, tc.want, got)
}
}
}