Browse Source

Fix zone related tests

Ask Bjørn Hansen 8 years ago
parent
commit
1429979241
3 changed files with 28 additions and 24 deletions
  1. 4 1
      Makefile
  2. 21 20
      server_test.go
  3. 3 3
      zones/zone.go

+ 4 - 1
Makefile

@@ -1,10 +1,13 @@
 all: templates.go
 all: templates.go
-	go build
+	./build
 
 
 templates.go: templates/*.html monitor.go
 templates.go: templates/*.html monitor.go
 	go generate
 	go generate
 
 
 test:
 test:
+	go test $(go list ./... | grep -v /vendor/)
+
+testrace:
 	go test -race $(go list ./... | grep -v /vendor/)
 	go test -race $(go list ./... | grep -v /vendor/)
 
 
 devel:
 devel:

+ 21 - 20
zones/zones_test.go → server_test.go

@@ -1,4 +1,4 @@
-package zones
+package main
 
 
 import (
 import (
 	"io"
 	"io"
@@ -6,6 +6,7 @@ import (
 	"os"
 	"os"
 	"testing"
 	"testing"
 
 
+	"github.com/abh/geodns/zones"
 	"github.com/miekg/dns"
 	"github.com/miekg/dns"
 	. "gopkg.in/check.v1"
 	. "gopkg.in/check.v1"
 )
 )
@@ -14,31 +15,31 @@ import (
 func Test(t *testing.T) { TestingT(t) }
 func Test(t *testing.T) { TestingT(t) }
 
 
 type ConfigSuite struct {
 type ConfigSuite struct {
-	srv   *Server
-	zones Zones
+	srv      *Server
+	zonelist zones.Zones
 }
 }
 
 
 var _ = Suite(&ConfigSuite{})
 var _ = Suite(&ConfigSuite{})
 
 
 func (s *ConfigSuite) SetUpSuite(c *C) {
 func (s *ConfigSuite) SetUpSuite(c *C) {
-	s.zones = make(Zones)
-	lastRead = map[string]*ZoneReadRecord{}
+	s.zonelist = make(zones.Zones)
+	lastRead = map[string]*zoneReadRecord{}
 	s.srv = &Server{}
 	s.srv = &Server{}
-	s.srv.zonesReadDir("dns", s.zones)
+	s.srv.zonesReadDir("dns", s.zonelist)
 }
 }
 
 
 func (s *ConfigSuite) TestReadConfigs(c *C) {
 func (s *ConfigSuite) TestReadConfigs(c *C) {
 	// Just check that example.com and test.example.org loaded, too.
 	// Just check that example.com and test.example.org loaded, too.
-	c.Check(s.zones["example.com"].Origin, Equals, "example.com")
-	c.Check(s.zones["test.example.org"].Origin, Equals, "test.example.org")
-	if s.zones["test.example.org"].Options.Serial == 0 {
+	c.Check(s.zonelist["example.com"].Origin, Equals, "example.com")
+	c.Check(s.zonelist["test.example.org"].Origin, Equals, "test.example.org")
+	if s.zonelist["test.example.org"].Options.Serial == 0 {
 		c.Log("Serial number is 0, should be set by file timestamp")
 		c.Log("Serial number is 0, should be set by file timestamp")
 		c.Fail()
 		c.Fail()
 	}
 	}
 
 
 	// The real tests are in test.example.com so we have a place
 	// The real tests are in test.example.com so we have a place
 	// to make nutty configuration entries
 	// to make nutty configuration entries
-	tz := s.zones["test.example.com"]
+	tz := s.zonelist["test.example.com"]
 
 
 	// test.example.com was loaded
 	// test.example.com was loaded
 	c.Check(tz.Origin, Equals, "test.example.com")
 	c.Check(tz.Origin, Equals, "test.example.com")
@@ -54,15 +55,15 @@ func (s *ConfigSuite) TestReadConfigs(c *C) {
 
 
 	/* test different cname targets */
 	/* test different cname targets */
 	c.Check(tz.Labels["www"].
 	c.Check(tz.Labels["www"].
-		firstRR(dns.TypeCNAME).(*dns.CNAME).
+		FirstRR(dns.TypeCNAME).(*dns.CNAME).
 		Target, Equals, "geo.bitnames.com.")
 		Target, Equals, "geo.bitnames.com.")
 
 
 	c.Check(tz.Labels["www-cname"].
 	c.Check(tz.Labels["www-cname"].
-		firstRR(dns.TypeCNAME).(*dns.CNAME).
+		FirstRR(dns.TypeCNAME).(*dns.CNAME).
 		Target, Equals, "bar.test.example.com.")
 		Target, Equals, "bar.test.example.com.")
 
 
 	c.Check(tz.Labels["www-alias"].
 	c.Check(tz.Labels["www-alias"].
-		firstRR(dns.TypeMF).(*dns.MF).
+		FirstRR(dns.TypeMF).(*dns.MF).
 		Mf, Equals, "www")
 		Mf, Equals, "www")
 
 
 	// The header name should just have a dot-prefix
 	// The header name should just have a dot-prefix
@@ -72,7 +73,7 @@ func (s *ConfigSuite) TestReadConfigs(c *C) {
 
 
 func (s *ConfigSuite) TestRemoveConfig(c *C) {
 func (s *ConfigSuite) TestRemoveConfig(c *C) {
 	// restore the dns.Mux
 	// restore the dns.Mux
-	defer s.srv.zonesReadDir("dns", s.zones)
+	defer s.srv.zonesReadDir("dns", s.zonelist)
 
 
 	dir, err := ioutil.TempDir("", "geodns-test.")
 	dir, err := ioutil.TempDir("", "geodns-test.")
 	if err != nil {
 	if err != nil {
@@ -97,16 +98,16 @@ func (s *ConfigSuite) TestRemoveConfig(c *C) {
 		c.Fail()
 		c.Fail()
 	}
 	}
 
 
-	s.srv.zonesReadDir(dir, s.zones)
-	c.Check(s.zones["test.example.org"].Origin, Equals, "test.example.org")
-	c.Check(s.zones["test2.example.org"].Origin, Equals, "test2.example.org")
+	s.srv.zonesReadDir(dir, s.zonelist)
+	c.Check(s.zonelist["test.example.org"].Origin, Equals, "test.example.org")
+	c.Check(s.zonelist["test2.example.org"].Origin, Equals, "test2.example.org")
 
 
 	os.Remove(dir + "/test2.example.org.json")
 	os.Remove(dir + "/test2.example.org.json")
 	os.Remove(dir + "/invalid.example.org.json")
 	os.Remove(dir + "/invalid.example.org.json")
 
 
-	s.srv.zonesReadDir(dir, s.zones)
-	c.Check(s.zones["test.example.org"].Origin, Equals, "test.example.org")
-	_, ok := s.zones["test2.example.org"]
+	s.srv.zonesReadDir(dir, s.zonelist)
+	c.Check(s.zonelist["test.example.org"].Origin, Equals, "test.example.org")
+	_, ok := s.zonelist["test2.example.org"]
 	c.Check(ok, Equals, false)
 	c.Check(ok, Equals, false)
 }
 }
 
 

+ 3 - 3
zones/zone.go

@@ -128,7 +128,7 @@ func (z *Zone) Close() {
 	}
 	}
 }
 }
 
 
-func (l *Label) firstRR(dnsType uint16) dns.RR {
+func (l *Label) FirstRR(dnsType uint16) dns.RR {
 	return l.Records[dnsType][0].RR
 	return l.Records[dnsType][0].RR
 }
 }
 
 
@@ -148,7 +148,7 @@ func (z *Zone) AddLabel(k string) *Label {
 }
 }
 
 
 func (z *Zone) SoaRR() dns.RR {
 func (z *Zone) SoaRR() dns.RR {
-	return z.Labels[""].firstRR(dns.TypeSOA)
+	return z.Labels[""].FirstRR(dns.TypeSOA)
 }
 }
 
 
 func (zone *Zone) AddSOA() {
 func (zone *Zone) AddSOA() {
@@ -232,7 +232,7 @@ func (z *Zone) FindLabels(s string, targets []string, qts []uint16) (*Label, uin
 					return z.Labels[s], qtype
 					return z.Labels[s], qtype
 				case dns.TypeMF:
 				case dns.TypeMF:
 					if label.Records[dns.TypeMF] != nil {
 					if label.Records[dns.TypeMF] != nil {
-						name = label.firstRR(dns.TypeMF).(*dns.MF).Mf
+						name = label.FirstRR(dns.TypeMF).(*dns.MF).Mf
 						// TODO: need to avoid loops here somehow
 						// TODO: need to avoid loops here somehow
 						return z.FindLabels(name, targets, qts)
 						return z.FindLabels(name, targets, qts)
 					}
 					}