mirror of
https://github.com/coredns/coredns.git
synced 2025-12-05 09:55:10 -05:00
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:
@@ -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
21
middleware/test/zone.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user