forked from abh/geodns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzone_test.go
113 lines (87 loc) · 4.13 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
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
package main
import (
"github.com/abh/geodns/Godeps/_workspace/src/github.com/miekg/dns"
. "github.com/abh/geodns/Godeps/_workspace/src/gopkg.in/check.v1"
)
func (s *ConfigSuite) TestExampleComZone(c *C) {
ex, ok := s.zones["test.example.com"]
c.Check(ok, Equals, true)
c.Check(ex, NotNil)
// test.example.com was loaded
c.Assert(ex.Labels, NotNil)
c.Check(ex.Logging.StatHat, Equals, true)
c.Check(ex.Logging.StatHatAPI, Equals, "abc-test")
c.Check(ex.Labels["weight"].MaxHosts, Equals, 1)
// Make sure that the empty "no.bar" zone gets skipped and "bar" is used
label, qtype := ex.findLabels("bar", []string{"no", "europe", "@"}, qTypes{dns.TypeA})
c.Check(label.Records[dns.TypeA], HasLen, 1)
c.Check(label.Records[dns.TypeA][0].RR.(*dns.A).A.String(), Equals, "192.168.1.2")
c.Check(qtype, Equals, dns.TypeA)
label, qtype = ex.findLabels("", []string{"@"}, qTypes{dns.TypeMX})
Mxs := label.Records[dns.TypeMX]
c.Check(Mxs, HasLen, 2)
c.Check(Mxs[0].RR.(*dns.MX).Mx, Equals, "mx.example.net.")
c.Check(Mxs[1].RR.(*dns.MX).Mx, Equals, "mx2.example.net.")
label, qtype = ex.findLabels("", []string{"dk", "europe", "@"}, qTypes{dns.TypeMX})
Mxs = label.Records[dns.TypeMX]
c.Check(Mxs, HasLen, 1)
c.Check(Mxs[0].RR.(*dns.MX).Mx, Equals, "mx-eu.example.net.")
c.Check(qtype, Equals, dns.TypeMX)
// look for multiple record types
label, qtype = ex.findLabels("www", []string{"@"}, qTypes{dns.TypeCNAME, dns.TypeA})
c.Check(label.Records[dns.TypeCNAME], HasLen, 1)
c.Check(qtype, Equals, dns.TypeCNAME)
// pretty.Println(ex.Labels[""].Records[dns.TypeNS])
label, qtype = ex.findLabels("", []string{"@"}, qTypes{dns.TypeNS})
Ns := label.Records[dns.TypeNS]
c.Check(Ns, HasLen, 2)
// Test that we get the expected NS records (in any order because
// of the configuration format used for this zone)
c.Check(Ns[0].RR.(*dns.NS).Ns, Matches, "^ns[12]\\.example\\.net.$")
c.Check(Ns[1].RR.(*dns.NS).Ns, Matches, "^ns[12]\\.example\\.net.$")
label, qtype = ex.findLabels("", []string{"@"}, qTypes{dns.TypeSPF})
Spf := label.Records[dns.TypeSPF]
c.Check(Spf, HasLen, 1)
c.Check(Spf[0].RR.(*dns.SPF).Txt[0], Equals, "v=spf1 ~all")
label, qtype = ex.findLabels("foo", []string{"@"}, qTypes{dns.TypeTXT})
Txt := label.Records[dns.TypeTXT]
c.Check(Txt, HasLen, 1)
c.Check(Txt[0].RR.(*dns.TXT).Txt[0], Equals, "this is foo")
label, qtype = ex.findLabels("weight", []string{"@"}, qTypes{dns.TypeTXT})
Txt = label.Records[dns.TypeTXT]
c.Check(Txt, HasLen, 2)
c.Check(Txt[0].RR.(*dns.TXT).Txt[0], Equals, "w1000")
c.Check(Txt[1].RR.(*dns.TXT).Txt[0], Equals, "w1")
//verify empty labels are created
label, qtype = ex.findLabels("a.b.c", []string{"@"}, qTypes{dns.TypeA})
c.Check(label.Records[dns.TypeA], HasLen, 1)
c.Check(label.Records[dns.TypeA][0].RR.(*dns.A).A.String(), Equals, "192.168.1.7")
label, qtype = ex.findLabels("b.c", []string{"@"}, qTypes{dns.TypeA})
c.Check(label.Records[dns.TypeA], HasLen, 0)
c.Check(label.Label, Equals, "b.c")
label, qtype = ex.findLabels("c", []string{"@"}, qTypes{dns.TypeA})
c.Check(label.Records[dns.TypeA], HasLen, 0)
c.Check(label.Label, Equals, "c")
//verify label is created
label, qtype = ex.findLabels("three.two.one", []string{"@"}, qTypes{dns.TypeA})
c.Check(label.Records[dns.TypeA], HasLen, 1)
c.Check(label.Records[dns.TypeA][0].RR.(*dns.A).A.String(), Equals, "192.168.1.5")
label, qtype = ex.findLabels("two.one", []string{"@"}, qTypes{dns.TypeA})
c.Check(label.Records[dns.TypeA], HasLen, 0)
c.Check(label.Label, Equals, "two.one")
//verify label isn't overwritten
label, qtype = ex.findLabels("one", []string{"@"}, qTypes{dns.TypeA})
c.Check(label.Records[dns.TypeA], HasLen, 1)
c.Check(label.Records[dns.TypeA][0].RR.(*dns.A).A.String(), Equals, "192.168.1.6")
}
func (s *ConfigSuite) TestExampleOrgZone(c *C) {
ex := s.zones["test.example.org"]
// test.example.org was loaded
c.Assert(ex.Labels, NotNil)
label, qtype := ex.findLabels("sub", []string{"@"}, qTypes{dns.TypeNS})
c.Assert(qtype, Equals, dns.TypeNS)
Ns := label.Records[dns.TypeNS]
c.Check(Ns, HasLen, 2)
c.Check(Ns[0].RR.(*dns.NS).Ns, Equals, "ns1.example.com.")
c.Check(Ns[1].RR.(*dns.NS).Ns, Equals, "ns2.example.com.")
}