-
Notifications
You must be signed in to change notification settings - Fork 35
/
zone_test.go
70 lines (62 loc) · 1.5 KB
/
zone_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
package zonedb
import (
"reflect"
"testing"
"unsafe"
"golang.org/x/net/idna"
)
// ToASCII normalizes a domain name or URL to ASCII/punycode.
func ToASCII(s string) string {
s, _ = idna.ToASCII(s)
return s
}
func TestSizeofZone(t *testing.T) {
var z Zone
t.Logf("sizeof Zone = %d", unsafe.Sizeof(z))
}
func TestLanguages(t *testing.T) {
tests := []struct {
domain string
want []string
}{
{"us", nil},
{"中国", []string{"zh-Hans-CN"}},
{"中國", []string{"zh-Hant-CN"}},
{"台湾", []string{"zh-Hans-TW"}},
{"台灣", []string{"zh-Hant-TW"}},
{"香港", []string{"zh-Hans-HK"}},
}
for _, tt := range tests {
t.Run(tt.domain, func(t *testing.T) {
domain := ToASCII(tt.domain)
z := ZoneMap[domain]
got := z.languages
if !reflect.DeepEqual(tt.want, got) {
t.Errorf("Zone.Language(), got: %#v, want: %#v", got, tt.want)
}
})
}
}
func TestRDAPURLs(t *testing.T) {
tests := []struct {
domain string
want []string
}{
{"nr", nil},
{"uk", []string{"https://rdap.nominet.uk/uk/"}},
{"co.uk", []string{"https://rdap.nominet.uk/uk/"}},
{"ac.uk", []string{"https://rdap.nominet.uk/uk/"}},
{"bbc", []string{"https://rdap.nominet.uk/bbc/"}},
{"lol", []string{"https://rdap.centralnic.com/lol/"}},
}
for _, tt := range tests {
t.Run(tt.domain, func(t *testing.T) {
domain := ToASCII(tt.domain)
z := ZoneMap[domain]
got := z.RDAPURLs()
if !reflect.DeepEqual(tt.want, got) {
t.Errorf("Zone.RDAPURLs(), got: %#v, want: %#v", got, tt.want)
}
})
}
}