coredns/middleware/proxy/lookup_test.go
Miek Gieben 84dfdab584 Cache elements of State
Cache the size and the do bit whenever someone asked for it. We can

probably add more:



PASS

BenchmarkStateDo-4  	100000000	        11.9 ns/op

BenchmarkStateSize-4	 5000000	       265 ns/op

ok  	github.com/miekg/coredns/middleware	2.828s



PASS

BenchmarkStateDo-4  	1000000000	         2.86 ns/op

BenchmarkStateSize-4	500000000	         3.10 ns/op

ok  	github.com/miekg/coredns/middleware	5.032s



This PR also includes some testing cleanups as well.
2016-04-04 08:19:06 +01:00

36 lines
915 B
Go

package proxy
import (
"io/ioutil"
"log"
"os"
"testing"
"github.com/miekg/coredns/middleware"
coretest "github.com/miekg/coredns/middleware/testing"
"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: &coretest.ResponseWriter{}, Req: new(dns.Msg)}
}