-
Notifications
You must be signed in to change notification settings - Fork 29
/
unbound_test.go
131 lines (122 loc) · 2.69 KB
/
unbound_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package unbound
import (
"fmt"
"runtime"
"sync"
"testing"
"github.com/miekg/dns"
)
func ExampleLookupCNAME() {
u := New()
defer u.Destroy()
if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
return
}
s, err := u.LookupCNAME("www.miek.nl.")
// A en AAAA lookup get canoncal name
if err != nil {
return
}
fmt.Printf("%+v\n", s)
}
func ExampleLookupIP() {
u := New()
defer u.Destroy()
if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
return
}
a, err := u.LookupIP("nlnetlabs.nl.")
if err != nil {
return
}
fmt.Printf("%+v\n", a)
}
func TestDotLess(t *testing.T) {
u := New()
defer u.Destroy()
if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
return
}
a, err := u.LookupTXT("gmail.com")
if err != nil {
return
}
for _, r := range a {
if len(r) == 0 {
t.Log("Failure to get the TXT from gmail.com")
t.Fail()
}
}
}
func TestUnicodeLookupHost(t *testing.T) {
u := New()
defer u.Destroy()
if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
return
}
a, err := u.LookupHost("☁→❄→☃→☀→☺→☂→☹→✝.ws.")
if err != nil {
t.Logf("Failed to lookup host %s\n", err.Error())
t.Fail()
}
if len(a) == 0 {
t.Log("Failure to get the A for ☁→❄→☃→☀→☺→☂→☹→✝.ws.")
t.Fail()
}
for _, r := range a {
if len(r) == 0 {
t.Log("Failure to get the A for ☁→❄→☃→☀→☺→☂→☹→✝.ws.")
t.Fail()
continue
}
t.Logf("Found %s\n", r)
}
}
func TestUnicodeResolve(t *testing.T) {
u := New()
defer u.Destroy()
if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
return
}
r, err := u.Resolve("☁→❄→☃→☀→☺→☂→☹→✝.ws.", dns.TypeA, dns.ClassINET)
if err != nil {
t.Log("Failure to get the A for ☁→❄→☃→☀→☺→☂→☹→✝.ws.")
t.Fail()
}
if !r.HaveData {
t.Log("Failure to get the A for ☁→❄→☃→☀→☺→☂→☹→✝.ws.")
t.Fail()
}
}
func TestStress(t *testing.T) {
domains := []string{"www.google.com.", "www.isc.org.", "www.outlook.com.", "miek.nl.", "doesnotexist.miek.nl."}
l := len(domains)
max := 8
procs := runtime.GOMAXPROCS(max)
wg := new(sync.WaitGroup)
wg.Add(max)
u := New()
defer u.Destroy()
if err := u.ResolvConf("/etc/resolv.conf"); err != nil {
return
}
for i := 0; i < max; i++ {
go func() {
for i := 0; i < 100; i++ {
d := domains[int(dns.Id())%l]
r, err := u.Resolve(d, dns.TypeA, dns.ClassINET)
if err != nil {
t.Log("failure to resolve: " + d)
continue
}
if !r.HaveData && d != "doesnotexist.miek.nl." {
t.Log("no data when resolving: " + d)
continue
}
}
wg.Done()
}()
}
wg.Wait()
runtime.GOMAXPROCS(procs)
}