From 09b05ded4624e32e175c541f53cf6821e6266010 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sat, 15 Feb 2014 08:03:40 +0000 Subject: [PATCH] Remove external DNS dependency This makes the test run 10x faster and does not require internet access for running the tests. --- client_test.go | 24 ++++++++++++++++++------ server_test.go | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/client_test.go b/client_test.go index a84fcd06..e8e2026f 100644 --- a/client_test.go +++ b/client_test.go @@ -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.") diff --git a/server_test.go b/server_test.go index ee51a2d3..00d19ba3 100644 --- a/server_test.go +++ b/server_test.go @@ -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",