-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterator_test.go
65 lines (53 loc) · 1.23 KB
/
iterator_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
package resolver
import (
"context"
"testing"
"github.com/miekg/dns"
"darvaza.org/resolver/pkg/exdns"
)
func TestRootLookup(t *testing.T) {
root, err := NewRootLookuper("")
if err != nil {
t.Fatal(err)
}
root.DisableAAAA() // for github sake
// Simple
testRootTypeA(t, root, "karasz.im", "95.216.149.141")
// Complex
testRootTypeA(t, root, "fda.my.salesforce.com", "")
// EDU
testRootTypeA(t, root, "www.seas.upenn.edu", "")
}
func TestRootLookupFrom(t *testing.T) {
root, err := NewRootLookuper(roots["a.root-servers.net"])
if err != nil {
t.Fatal(err)
}
root.DisableAAAA() // for github sake
// Simple
testRootTypeA(t, root, "karasz.im", "95.216.149.141")
}
func testRootTypeA(t *testing.T, h Lookuper, name, address string) {
z, err := h.Lookup(context.TODO(), name, dns.TypeA)
if err != nil {
t.Errorf("%s: %s", name, err.Error())
return
}
rr := exdns.GetFirstAnswer[*dns.A](z)
if rr == nil {
if address != "" {
t.Errorf("%s: no answer (expected %s)", name, address)
} else {
t.Errorf("%s: no answer", name)
}
return
}
first := rr.A.String()
if address != "" {
if first != address {
t.Errorf("%s: %s (expected %s)", name, first, address)
return
}
}
t.Logf("%s: %s", name, first)
}