-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathutils_test.go
99 lines (76 loc) · 2.45 KB
/
utils_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"regexp"
"testing"
"github.com/honwen/golibs/cip"
"github.com/honwen/golibs/domain"
"github.com/ysmood/got"
)
func TestContainsCIDRString(t *testing.T) {
_, err := containsCIDRString("127.0.0.0/8", "128.0.0.1")
got.T(t).NotNil(err)
is, _ := containsCIDRString("127.0.0.0/8", "128.0.0.1/32")
got.T(t).False(is)
is, _ = containsCIDRString("127.0.0.0/8", "127.0.0.99/32")
got.T(t).True(is)
}
func TestGetIPv4(t *testing.T) {
funcs["myip"] = cip.MyIPv4
ip4 := myip()
got.T(t).True(regexp.MustCompile(cip.RegxIPv4).MatchString(ip4) || len(ip4) == 0)
}
func TestGetIPv6(t *testing.T) {
funcs["myip"] = cip.MyIPv6
ip6 := myip()
got.T(t).True(regexp.MustCompile(cip.RegxIPv6).MatchString(ip6) || len(ip6) == 0)
}
func TestResloveIPv4(t *testing.T) {
funcs["reslove"] = cip.ResloveIPv4
got.T(t).Has([]string{"8.8.8.8", "8.8.4.4"}, reslove("dns.google"))
got.T(t).Has([]string{"223.6.6.6", "223.5.5.5"}, reslove("dns.alidns.com"))
}
func TestResloveIPv6(t *testing.T) {
funcs["reslove"] = cip.ResloveIPv6
got.T(t).Has([]string{"2001:4860:4860::8844", "2001:4860:4860::8888"}, reslove("dns.google"))
got.T(t).Has([]string{"2400:3200::1", "2400:3200:baba::1"}, reslove("dns.alidns.com"))
}
func TestSplitDomain001(t *testing.T) {
rr, domain := domain.SplitDomainToRR("a.example.com")
got.T(t).Eq(rr, "a")
got.T(t).Eq(domain, "example.com")
}
func TestSplitDomain002(t *testing.T) {
rr, domain := domain.SplitDomainToRR("example.com")
got.T(t).Eq(rr, "@")
got.T(t).Eq(domain, "example.com")
}
func TestSplitDomain003(t *testing.T) {
rr, domain := domain.SplitDomainToRR("*.example.com")
got.T(t).Eq(rr, "*")
got.T(t).Eq(domain, "example.com")
}
func TestSplitDomain004(t *testing.T) {
rr, domain := domain.SplitDomainToRR("*.a.example.com")
got.T(t).Eq(rr, "*.a")
got.T(t).Eq(domain, "example.com")
}
func TestSplitDomain005(t *testing.T) {
rr, domain := domain.SplitDomainToRR("*.b.a.example.com")
got.T(t).Eq(rr, "*.b.a")
got.T(t).Eq(domain, "example.com")
}
func TestSplitDomain006(t *testing.T) {
rr, domain := domain.SplitDomainToRR("a.example.co.kr")
got.T(t).Eq(rr, "a")
got.T(t).Eq(domain, "example.co.kr")
}
func TestSplitDomain007(t *testing.T) {
rr, domain := domain.SplitDomainToRR("*.a.example.co.kr")
got.T(t).Eq(rr, "*.a")
got.T(t).Eq(domain, "example.co.kr")
}
func TestSplitDomain008(t *testing.T) {
rr, domain := domain.SplitDomainToRR("example.co.kr")
got.T(t).Eq(rr, "@")
got.T(t).Eq(domain, "example.co.kr")
}