coredns/plugin/pkg/dnstest/server_test.go
Miek Gieben 284061eee7 pkg: add dnstest (#1098)
Add a full test server impl in this new package + tests. Move
dnsrecorder into this package as well and finish up the commented out
tests that were left in the old dnsrecorder package.

Update all callers and tests.
2017-09-21 15:15:47 +01:00

28 lines
556 B
Go

package dnstest
import (
"testing"
"github.com/miekg/dns"
)
func TestNewServer(t *testing.T) {
s := NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
ret := new(dns.Msg)
ret.SetReply(r)
w.WriteMsg(ret)
})
defer s.Close()
c := new(dns.Client)
c.Net = "tcp"
m := new(dns.Msg)
m.SetQuestion("example.org.", dns.TypeSOA)
ret, _, err := c.Exchange(m, s.Addr)
if err != nil {
t.Fatalf("Could not send message to dnstest.Server: %s", err)
}
if ret.Id != m.Id {
t.Fatalf("Msg ID's should match, expected %d, got %d", m.Id, ret.Id)
}
}