Remove external DNS dependency

This makes the test run 10x faster and does not require internet
access for running the tests.
This commit is contained in:
Miek Gieben 2014-02-15 08:03:40 +00:00
parent 0258525f20
commit 09b05ded46
2 changed files with 20 additions and 8 deletions

View File

@ -9,12 +9,26 @@ import (
"time"
)
func newTestServer(t *testing.T) {
// Defined in server_test.go
HandleFunc("miek.nl.", HelloServer)
HandleFunc("example.com.", AnotherHelloServer)
go func() {
err := ListenAndServe(":8063", "udp", nil)
if err != nil {
t.Log("ListenAndServe: ", err.Error())
t.Fatal()
}
}()
time.Sleep(4e8)
}
func TestClientSync(t *testing.T) {
m := new(Msg)
m.SetQuestion("miek.nl.", TypeSOA)
c := new(Client)
r, _, _ := c.Exchange(m, "37.251.95.53:53")
r, _, _ := c.Exchange(m, "127.0.0.1:6053")
if r != nil && r.Rcode != RcodeSuccess {
t.Log("Failed to get an valid answer")
@ -28,11 +42,9 @@ func TestClientEDNS0(t *testing.T) {
m.SetQuestion("miek.nl.", TypeDNSKEY)
m.SetEdns0(2048, true)
//edns.Option = make([]Option, 1)
//edns.SetNsid("") // Empty to request it
c := new(Client)
r, _, _ := c.Exchange(m, "37.251.95.53:53")
r, _, _ := c.Exchange(m, "127.0.0.1:6053")
if r != nil && r.Rcode != RcodeSuccess {
t.Log("Failed to get an valid answer")
@ -51,7 +63,7 @@ func TestSingleSingleInflight(t *testing.T) {
ch := make(chan time.Duration)
for i := 0; i < nr; i++ {
go func() {
_, rtt, _ := c.Exchange(m, "37.251.95.53:53")
_, rtt, _ := c.Exchange(m, "127.0.0.1:6053")
ch <- rtt
}()
}
@ -126,7 +138,7 @@ func TestClientAXFRMultipleEnvelopes(t *testing.T) {
}
*/
// not really a test, but shows how to use update leases
// ExapleUpdateLeaseTSIG shows how to update a lease signed with TSIG.
func ExampleUpdateLeaseTSIG(t *testing.T) {
m := new(Msg)
m.SetUpdate("t.local.ip6.io.")

View File

@ -165,7 +165,7 @@ func TestRootServer(t *testing.T) {
var MAXREC = 0
func handleQuery(resp ResponseWriter, req *Msg) {
func HelloServerLargeResponse(resp ResponseWriter, req *Msg) {
m := new(Msg)
m.SetReply(req)
m.Authoritative = true
@ -186,7 +186,7 @@ func handleQuery(resp ResponseWriter, req *Msg) {
func TestServingLargeResponses(t *testing.T) {
mux := NewServeMux()
mux.HandleFunc("example.", handleQuery)
mux.HandleFunc("example.", HelloServerLargeResponse)
server := &Server{
Addr: "127.0.0.1:10000",