浏览代码

Add tests for NS records

Ask Bjørn Hansen 12 年之前
父节点
当前提交
a515734ef6
共有 4 个文件被更改,包括 39 次插入1 次删除
  1. 6 0
      dns/test.example.org.json
  2. 5 0
      serve_test.go
  3. 4 0
      zone.go
  4. 24 1
      zone_test.go

+ 6 - 0
dns/test.example.org.json

@@ -3,6 +3,12 @@
         "bad-example-there-really-should-be-an-ns-record-at-the-apex-here": {},
         "bad-example-there-really-should-be-an-ns-record-at-the-apex-here": {},
         "bar": {
         "bar": {
             "a": [ [ "192.168.1.2" ] ]
             "a": [ [ "192.168.1.2" ] ]
+        },
+        "sub-alias": {
+        	"alias": "sub"
+        },
+        "sub": {
+        	"ns": [ "ns1.example.com", "ns2.example.com" ]
         }
         }
     }
     }
 }
 }

+ 5 - 0
serve_test.go

@@ -97,6 +97,11 @@ func (s *ServeSuite) TestServingAliases(c *C) {
 	if len(r.Answer) > 0 {
 	if len(r.Answer) > 0 {
 		c.Check(r.Answer[0].(*dns.CNAME).Target, Equals, "geo-europe.bitnames.com.")
 		c.Check(r.Answer[0].(*dns.CNAME).Target, Equals, "geo-europe.bitnames.com.")
 	}
 	}
+
+	// Alias to Ns records
+	r = exchange(c, "sub-alias.test.example.org.", dns.TypeNS)
+	c.Check(r.Answer[0].(*dns.NS).Ns, Equals, "ns1.example.com.")
+
 }
 }
 
 
 func (s *ServeSuite) TestServingEDNS(c *C) {
 func (s *ServeSuite) TestServingEDNS(c *C) {

+ 4 - 0
zone.go

@@ -119,6 +119,10 @@ func (z *Zone) SoaRR() dns.RR {
 	return z.Labels[""].firstRR(dns.TypeSOA)
 	return z.Labels[""].firstRR(dns.TypeSOA)
 }
 }
 
 
+// Find label "s" in country "cc" falling back to the appropriate
+// continent and the global label name as needed. Looks for the
+// first available qType at each targeting level. Return a Label
+// and the qtype that was "found"
 func (z *Zone) findLabels(s, cc string, qts qTypes) (*Label, uint16) {
 func (z *Zone) findLabels(s, cc string, qts qTypes) (*Label, uint16) {
 
 
 	selectors := []string{}
 	selectors := []string{}

+ 24 - 1
zone_test.go

@@ -5,7 +5,7 @@ import (
 	. "launchpad.net/gocheck"
 	. "launchpad.net/gocheck"
 )
 )
 
 
-func (s *ConfigSuite) TestZone(c *C) {
+func (s *ConfigSuite) TestExampleComZone(c *C) {
 	ex := s.zones["test.example.com"]
 	ex := s.zones["test.example.com"]
 
 
 	// test.example.com was loaded
 	// test.example.com was loaded
@@ -38,4 +38,27 @@ func (s *ConfigSuite) TestZone(c *C) {
 	label, qtype = ex.findLabels("www", "", qTypes{dns.TypeCNAME, dns.TypeA})
 	label, qtype = ex.findLabels("www", "", qTypes{dns.TypeCNAME, dns.TypeA})
 	c.Check(label.Records[dns.TypeCNAME], HasLen, 1)
 	c.Check(label.Records[dns.TypeCNAME], HasLen, 1)
 	c.Check(qtype, Equals, dns.TypeCNAME)
 	c.Check(qtype, Equals, dns.TypeCNAME)
+
+	label, qtype = ex.findLabels("", "", qTypes{dns.TypeNS})
+	Ns := label.Records[dns.TypeNS]
+	c.Check(Ns, HasLen, 2)
+	c.Check(Ns[0].RR.(*dns.NS).Ns, Equals, "ns1.example.net.")
+	c.Check(Ns[1].RR.(*dns.NS).Ns, Equals, "ns2.example.net.")
+
+}
+
+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", "", 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.")
+
 }
 }