coredns/test/tests.go
Miek Gieben 0ea2a6088d Add TestServer (#102)
Add a fullblown testing server. This allows us to do integration tests.

Also add a basic proxy test. Further tests will test etcd proxy
and stub zone communication and other "wildish" configurations.
Redo the server startup, so we can access the ports it listens on when
it has started up (with dns.ActivateAndServer).

Extend the .travis file to download etcd and test for that as well.

Put integration tests in test dir
2016-04-10 18:50:11 +01:00

40 lines
874 B
Go

package test
import (
"testing"
"time"
"github.com/miekg/coredns/core"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/server"
"github.com/miekg/dns"
)
func testMsg(zone string, typ uint16, o *dns.OPT) *dns.Msg {
m := new(dns.Msg)
m.SetQuestion(zone, typ)
if o != nil {
m.Extra = []dns.RR{o}
}
return m
}
func testExchange(m *dns.Msg, server, net string) (*dns.Msg, error) {
c := new(dns.Client)
c.Net = net
return middleware.Exchange(c, m, server)
}
// testServer returns a test server and the tcp and udp listeners addresses.
func testServer(t *testing.T, corefile string) (*server.Server, string, string, error) {
srv, err := core.TestServer(t, corefile)
if err != nil {
return nil, "", "", err
}
go srv.ListenAndServe()
time.Sleep(1 * time.Second)
tcp, udp := srv.LocalAddr()
return srv, tcp.String(), udp.String(), nil
}