-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToHostAndPort_test.go
80 lines (53 loc) · 1.7 KB
/
ToHostAndPort_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
package url
import net_url "net/url"
import "testing"
func TestToHostAndPort(t *testing.T) {
t.Run("Host", func(t *testing.T) {
url, _ := net_url.Parse("http://sub.domain.example.com/index.html")
expected := "sub.domain.example.com:80"
host := ToHostAndPort(url)
if host != expected {
t.Errorf("Expected '%s' but got '%s'", expected, host)
}
})
t.Run("Host and Port", func(t *testing.T) {
url, _ := net_url.Parse("http://sub.domain.example.com:1337/index.html")
expected := "sub.domain.example.com:1337"
host := ToHostAndPort(url)
if host != expected {
t.Errorf("Expected '%s' but got '%s'", expected, host)
}
})
t.Run("IPv4", func(t *testing.T) {
url, _ := net_url.Parse("https://1.33.33.7/index.html")
expected := "1.33.33.7:443"
host := ToHostAndPort(url)
if host != expected {
t.Errorf("Expected '%s' but got '%s'", expected, host)
}
})
t.Run("IPv4 and Port", func(t *testing.T) {
url, _ := net_url.Parse("https://1.33.33.7:1337/index.html")
expected := "1.33.33.7:1337"
host := ToHostAndPort(url)
if host != expected {
t.Errorf("Expected '%s' but got '%s'", expected, host)
}
})
t.Run("IPv6", func(t *testing.T) {
url, _ := net_url.Parse("http://[fe80::1337]/index.html")
expected := "[fe80:0000:0000:0000:0000:0000:0000:1337]:80"
host := ToHostAndPort(url)
if host != expected {
t.Errorf("Expected '%s' but got '%s'", expected, host)
}
})
t.Run("IPv6 and Port", func(t *testing.T) {
url, _ := net_url.Parse("http://[fe80::1337]:1337/index.html")
expected := "[fe80:0000:0000:0000:0000:0000:0000:1337]:1337"
host := ToHostAndPort(url)
if host != expected {
t.Errorf("Expected '%s' but got '%s'", expected, host)
}
})
}