forked from miekg/dns
-
Notifications
You must be signed in to change notification settings - Fork 3
/
zone_test.go
45 lines (41 loc) · 1.03 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
package dns
import "testing"
func TestRadixName(t *testing.T) {
tests := map[string]string{".": ".",
"www.miek.nl.": ".nl.miek.www",
"miek.nl.": ".nl.miek",
"mi\\.ek.nl.": ".nl.mi\\.ek",
`mi\\.ek.nl.`: `.nl.ek.mi\\`,
"": "."}
for i, o := range tests {
t.Logf("%s %v\n", i, SplitLabels(i))
if x := toRadixName(i); x != o {
t.Logf("%s should convert to %s, not %s\n", i, o, x)
t.Fail()
}
}
}
func TestInsert(t *testing.T) {
z := NewZone("miek.nl.")
mx, _ := NewRR("foo.miek.nl. MX 10 mx.miek.nl.")
z.Insert(mx)
_, exact := z.Find("foo.miek.nl.")
if exact != true {
t.Fail() // insert broken?
}
}
func TestRemove(t *testing.T) {
z := NewZone("miek.nl.")
mx, _ := NewRR("foo.miek.nl. MX 10 mx.miek.nl.")
z.Insert(mx)
zd, exact := z.Find("foo.miek.nl.")
if exact != true {
t.Fail() // insert broken?
}
z.Remove(mx)
zd, exact = z.Find("foo.miek.nl.")
if exact != false {
println(zd.String())
t.Errorf("zd(%s) exact(%s) still exists", zd, exact) // it should no longer be in the zone
}
}