All (non etcd) tests are now local (#105)

We don't need to network to do tests, we up enough local servers
to we don't need to forward to,s say 8.8.8.8
This commit is contained in:
Miek Gieben
2016-04-11 15:56:22 +01:00
parent 31ce53f514
commit 9f651a397b
6 changed files with 89 additions and 45 deletions

View File

@@ -1,36 +0,0 @@
package proxy
import (
"io/ioutil"
"log"
"os"
"testing"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/test"
"github.com/miekg/dns"
)
func TestLookupProxy(t *testing.T) {
// TODO(miek): make this fakeDNS backend and ask the question locally
log.SetOutput(ioutil.Discard)
defer log.SetOutput(os.Stderr)
p := New([]string{"8.8.8.8:53"})
resp, err := p.Lookup(fakeState(), "example.org.", dns.TypeA)
if err != nil {
t.Error("Expected to receive reply, but didn't")
}
// expect answer section with A record in it
if len(resp.Answer) == 0 {
t.Error("Expected to at least one RR in the answer section, got none")
}
if resp.Answer[0].Header().Rrtype != dns.TypeA {
t.Error("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
}
}
func fakeState() middleware.State {
return middleware.State{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
}

21
middleware/test/zone.go Normal file
View File

@@ -0,0 +1,21 @@
package test
import (
"io/ioutil"
"os"
"testing"
)
// Zone will create a temporary file on disk and returns the name and
// cleanup function to remove it later.
func Zone(t *testing.T, dir, zonefile string) (string, func(), error) {
f, err := ioutil.TempFile(dir, "go-test-zone")
if err != nil {
return "", nil, err
}
if err := ioutil.WriteFile(f.Name(), []byte(zonefile), 0644); err != nil {
return "", nil, err
}
rmFunc := func() { os.Remove(f.Name()) }
return f.Name(), rmFunc, nil
}