Browse Source

Only use zones with actual data

Reported by Maoz Zadok
Ask Bjørn Hansen 13 years ago
parent
commit
3124a4df94
3 changed files with 17 additions and 1 deletions
  1. 1 0
      dns/example.com.json
  2. 1 1
      types.go
  3. 15 0
      zone_test.go

+ 1 - 0
dns/example.com.json

@@ -15,6 +15,7 @@
       "a": [ [ "192.168.1.2", 10 ] ],
       "a": [ [ "192.168.1.2", 10 ] ],
       "ttl": "601"
       "ttl": "601"
     },
     },
+    "bar.no": { "a": [] },
     "0": {
     "0": {
       "a": [ [ "192.168.0.1", 10 ] ]
       "a": [ [ "192.168.0.1", 10 ] ]
     },
     },

+ 1 - 1
types.go

@@ -90,7 +90,7 @@ func (z *Zone) findLabels(s, cc string, qtype uint16) *Label {
 
 
 			// return the label if it has the right records
 			// return the label if it has the right records
 			// TODO(ask) Should this also look for CNAME records?
 			// TODO(ask) Should this also look for CNAME records?
-			if label.Records[qtype] != nil {
+			if label.Records[qtype] != nil && len(label.Records[qtype]) > 0 {
 				return label
 				return label
 			}
 			}
 		}
 		}

+ 15 - 0
zone_test.go

@@ -0,0 +1,15 @@
+package main
+
+import (
+	"github.com/miekg/dns"
+	. "launchpad.net/gocheck"
+)
+
+func (s *ConfigSuite) TestZone(c *C) {
+	ex := s.zones["example.com"]
+	c.Check(ex.Labels["weight"].MaxHosts, Equals, 1)
+
+	// Make sure that the empty "no.bar" zone gets skipped and "bar" is used
+	label := ex.findLabels("bar", "no", dns.TypeA)
+	c.Check(label.Records[dns.TypeA], HasLen, 1)
+}