-
Notifications
You must be signed in to change notification settings - Fork 1
/
ToRecordName_test.go
80 lines (53 loc) · 1.75 KB
/
ToRecordName_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 tunnel
import net_url "net/url"
import "testing"
func TestToRecordName(t *testing.T) {
t.Run("Domain", func(t *testing.T) {
url, _ := net_url.Parse("http://sub.domain.example.com/index.html")
expected := "sub.domain.example.com"
name := ToRecordName(url)
if expected != name {
t.Errorf("Expected '%s' but got '%s'", expected, name)
}
})
t.Run("Domain and Port", func(t *testing.T) {
url, _ := net_url.Parse("http://sub.domain.example.com:1337/index.html")
expected := "sub.domain.example.com"
name := ToRecordName(url)
if expected != name {
t.Errorf("Expected '%s' but got '%s'", expected, name)
}
})
t.Run("IPv4", func(t *testing.T) {
url, _ := net_url.Parse("http://1.3.3.7/index.html")
expected := "7.3.3.1.in-addr.arpa"
name := ToRecordName(url)
if expected != name {
t.Errorf("Expected '%s' but got '%s'", expected, name)
}
})
t.Run("IPv4 and Port", func(t *testing.T) {
url, _ := net_url.Parse("http://1.3.3.7:1337/index.html")
expected := "7.3.3.1.in-addr.arpa"
name := ToRecordName(url)
if expected != name {
t.Errorf("Expected '%s' but got '%s'", expected, name)
}
})
t.Run("IPv6", func(t *testing.T) {
url, _ := net_url.Parse("http://[fe80::1337]/index.html")
expected := "7.3.3.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa"
name := ToRecordName(url)
if expected != name {
t.Errorf("Expected '%s' but got '%s'", expected, name)
}
})
t.Run("IPv6 and Port", func(t *testing.T) {
url, _ := net_url.Parse("http://[fe80::1337]:1337/index.html")
expected := "7.3.3.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa"
name := ToRecordName(url)
if expected != name {
t.Errorf("Expected '%s' but got '%s'", expected, name)
}
})
}