diff options
author | 2016-09-07 11:10:16 +0100 | |
---|---|---|
committer | 2016-09-07 11:10:16 +0100 | |
commit | d1f17fa7e061d91aa0af7e1fb959a68db899c812 (patch) | |
tree | 0f828a0e7bd8ca86051a721dae48e8c19a0a2f0e /test | |
parent | 684330fd28f65a7a8d1ad01fb4c6c5db78240f29 (diff) | |
download | coredns-d1f17fa7e061d91aa0af7e1fb959a68db899c812.tar.gz coredns-d1f17fa7e061d91aa0af7e1fb959a68db899c812.tar.zst coredns-d1f17fa7e061d91aa0af7e1fb959a68db899c812.zip |
Cleanup: put middleware helper functions in pkgs (#245)
Move all (almost all) Go files in middleware into their
own packages. This makes for better naming and discoverability.
Lot of changes elsewhere to make this change.
The middleware.State was renamed to request.Request which is better,
but still does not cover all use-cases. It was also moved out middleware
because it is used by `dnsserver` as well.
A pkg/dnsutil packages was added for shared, handy, dns util functions.
All normalize functions are now put in normalize.go
Diffstat (limited to 'test')
-rw-r--r-- | test/etcd_test.go | 4 | ||||
-rw-r--r-- | test/proxy_test.go | 4 | ||||
-rw-r--r-- | test/server_test.go | 13 | ||||
-rw-r--r-- | test/tests.go | 12 |
4 files changed, 11 insertions, 22 deletions
diff --git a/test/etcd_test.go b/test/etcd_test.go index 6645e9931..6f3c0b39a 100644 --- a/test/etcd_test.go +++ b/test/etcd_test.go @@ -9,11 +9,11 @@ import ( "testing" "time" - "github.com/miekg/coredns/middleware" "github.com/miekg/coredns/middleware/etcd" "github.com/miekg/coredns/middleware/etcd/msg" "github.com/miekg/coredns/middleware/proxy" "github.com/miekg/coredns/middleware/test" + "github.com/miekg/coredns/request" etcdc "github.com/coreos/etcd/client" "github.com/miekg/dns" @@ -67,7 +67,7 @@ func TestEtcdStubAndProxyLookup(t *testing.T) { } p := proxy.New([]string{udp}) // use udp port from the server - state := middleware.State{W: &test.ResponseWriter{}, Req: new(dns.Msg)} + state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)} resp, err := p.Lookup(state, "example.com.", dns.TypeA) if err != nil { t.Error("Expected to receive reply, but didn't") diff --git a/test/proxy_test.go b/test/proxy_test.go index 96a2c4c0d..e946f4354 100644 --- a/test/proxy_test.go +++ b/test/proxy_test.go @@ -5,9 +5,9 @@ import ( "log" "testing" - "github.com/miekg/coredns/middleware" "github.com/miekg/coredns/middleware/proxy" "github.com/miekg/coredns/middleware/test" + "github.com/miekg/coredns/request" "github.com/miekg/dns" ) @@ -46,7 +46,7 @@ func TestLookupProxy(t *testing.T) { log.SetOutput(ioutil.Discard) p := proxy.New([]string{udp}) - state := middleware.State{W: &test.ResponseWriter{}, Req: new(dns.Msg)} + state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)} resp, err := p.Lookup(state, "example.org.", dns.TypeA) if err != nil { t.Fatal("Expected to receive reply, but didn't") diff --git a/test/server_test.go b/test/server_test.go index a03285bf3..903922a04 100644 --- a/test/server_test.go +++ b/test/server_test.go @@ -17,7 +17,7 @@ func TestProxyToChaosServer(t *testing.T) { t.Fatalf("could not get CoreDNS serving instance: %s", err) } - udpChaos, tcpChaos := CoreDNSServerPorts(chaos, 0) + udpChaos, _ := CoreDNSServerPorts(chaos, 0) defer chaos.Stop() corefileProxy := `.:0 { @@ -32,24 +32,23 @@ func TestProxyToChaosServer(t *testing.T) { udp, _ := CoreDNSServerPorts(proxy, 0) defer proxy.Stop() - chaosTest(t, udpChaos, "udp") - chaosTest(t, tcpChaos, "tcp") + chaosTest(t, udpChaos) - chaosTest(t, udp, "udp") + chaosTest(t, udp) // chaosTest(t, tcp, "tcp"), commented out because we use the original transport to reach the // proxy and we only forward to the udp port. } -func chaosTest(t *testing.T, server, net string) { +func chaosTest(t *testing.T, server string) { m := Msg("version.bind.", dns.TypeTXT, nil) m.Question[0].Qclass = dns.ClassCHAOS - r, err := Exchange(m, server, net) + r, err := dns.Exchange(m, server) if err != nil { t.Fatalf("Could not send message: %s", err) } if r.Rcode != dns.RcodeSuccess || len(r.Answer) == 0 { - t.Fatalf("Expected successful reply on %s, got %s", net, dns.RcodeToString[r.Rcode]) + t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode]) } if r.Answer[0].String() != `version.bind. 0 CH TXT "CoreDNS-001"` { t.Fatalf("Expected version.bind. reply, got %s", r.Answer[0].String()) diff --git a/test/tests.go b/test/tests.go index 0f9d12bae..fb2853e9a 100644 --- a/test/tests.go +++ b/test/tests.go @@ -1,10 +1,6 @@ package test -import ( - "github.com/miekg/coredns/middleware" - - "github.com/miekg/dns" -) +import "github.com/miekg/dns" func Msg(zone string, typ uint16, o *dns.OPT) *dns.Msg { m := new(dns.Msg) @@ -14,9 +10,3 @@ func Msg(zone string, typ uint16, o *dns.OPT) *dns.Msg { } return m } - -func Exchange(m *dns.Msg, server, net string) (*dns.Msg, error) { - c := new(dns.Client) - c.Net = net - return middleware.Exchange(c, m, server) -} |