|
@@ -2,7 +2,10 @@ package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"github.com/miekg/dns"
|
|
"github.com/miekg/dns"
|
|
|
|
+ "io"
|
|
|
|
+ "io/ioutil"
|
|
. "launchpad.net/gocheck"
|
|
. "launchpad.net/gocheck"
|
|
|
|
+ "os"
|
|
"testing"
|
|
"testing"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -15,10 +18,12 @@ type ConfigSuite struct {
|
|
|
|
|
|
var _ = Suite(&ConfigSuite{})
|
|
var _ = Suite(&ConfigSuite{})
|
|
|
|
|
|
-func (s *ConfigSuite) TestReadConfigs(c *C) {
|
|
|
|
|
|
+func (s *ConfigSuite) SetUpSuite(c *C) {
|
|
s.zones = make(Zones)
|
|
s.zones = make(Zones)
|
|
zonesReadDir("dns", s.zones)
|
|
zonesReadDir("dns", s.zones)
|
|
|
|
+}
|
|
|
|
|
|
|
|
+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["example.com"].Origin, Equals, "example.com")
|
|
c.Check(s.zones["test.example.org"].Origin, Equals, "test.example.org")
|
|
c.Check(s.zones["test.example.org"].Origin, Equals, "test.example.org")
|
|
@@ -46,3 +51,54 @@ func (s *ConfigSuite) TestReadConfigs(c *C) {
|
|
Mf, Equals, "www")
|
|
Mf, Equals, "www")
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (s *ConfigSuite) TestRemoveConfig(c *C) {
|
|
|
|
+ // restore the dns.Mux
|
|
|
|
+ defer zonesReadDir("dns", s.zones)
|
|
|
|
+
|
|
|
|
+ dir, err := ioutil.TempDir("", "geodns-test.")
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Fail()
|
|
|
|
+ }
|
|
|
|
+ defer os.RemoveAll(dir)
|
|
|
|
+
|
|
|
|
+ _, err = CopyFile(c, "dns/test.example.org.json", dir+"/test.example.org.json")
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Log(err)
|
|
|
|
+ c.Fail()
|
|
|
|
+ }
|
|
|
|
+ _, err = CopyFile(c, "dns/test.example.org.json", dir+"/test2.example.org.json")
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Log(err)
|
|
|
|
+ c.Fail()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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")
|
|
|
|
+
|
|
|
|
+ os.Remove(dir + "/test2.example.org.json")
|
|
|
|
+
|
|
|
|
+ zonesReadDir(dir, s.zones)
|
|
|
|
+ c.Check(s.zones["test.example.org"].Origin, Equals, "test.example.org")
|
|
|
|
+ _, ok := s.zones["test2.example.org"]
|
|
|
|
+ c.Check(ok, Equals, false)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func CopyFile(c *C, src, dst string) (int64, error) {
|
|
|
|
+ sf, err := os.Open(src)
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Log("Could not copy", src, "to", dst, "because", err)
|
|
|
|
+ c.Fail()
|
|
|
|
+ return 0, err
|
|
|
|
+ }
|
|
|
|
+ defer sf.Close()
|
|
|
|
+ df, err := os.Create(dst)
|
|
|
|
+ if err != nil {
|
|
|
|
+ c.Log("Could not copy", src, "to", dst, "because", err)
|
|
|
|
+ c.Fail()
|
|
|
|
+ return 0, err
|
|
|
|
+ }
|
|
|
|
+ defer df.Close()
|
|
|
|
+ return io.Copy(df, sf)
|
|
|
|
+}
|