aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2019-01-13 16:54:49 +0000
committerGravatar GitHub <noreply@github.com> 2019-01-13 16:54:49 +0000
commit9c16ed1d14f570f27b4ff9cb89845a3a1548a776 (patch)
tree8050afa683fdb3f2e1efa1dd2e3a35a680d689d0 /test
parent6b56a9c92130d50cee9bd92aaee500dbccff395f (diff)
downloadcoredns-9c16ed1d14f570f27b4ff9cb89845a3a1548a776.tar.gz
coredns-9c16ed1d14f570f27b4ff9cb89845a3a1548a776.tar.zst
coredns-9c16ed1d14f570f27b4ff9cb89845a3a1548a776.zip
Default to upstream to self (#2436)
* Default to upstream to self This is a backwards incompatible change. This is a massive (cleanup) PR where we default to resolving external names by the coredns process itself, instead of directly forwarding them to some upstream. This ignores any arguments `upstream` may have had and makes it depend on proxy/forward configuration in the Corefile. This allows resolved upstream names to be cached and we have better healthchecking of the upstreams. It also means there is only one way to resolve names, by either using the proxy or forward plugin. The proxy/forward lookup.go functions have been removed. This also lessen the dependency on proxy, meaning deprecating proxy will become easier. Some tests have been removed as well, or moved to the top-level test directory as they now require a full coredns process instead of just the plugin. For the etcd plugin, the entire StubZone resolving is *dropped*! This was a hacky (but working) solution to say the least. If someone cares deeply it can be brought back (maybe)? The pkg/upstream is now very small and almost does nothing. Also the New() function was changed to return a pointer to upstream.Upstream. It also returns only one parameter, so any stragglers using it will encounter a compile error. All documentation has been adapted. This affected the following plugins: * etcd * file * auto * secondary * federation * template * route53 A followup PR will make any upstream directives with arguments an error, right now they are ignored. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix etcd build - probably still fails unit test Signed-off-by: Miek Gieben <miek@miek.nl> * Slightly smarter lookup check in upstream Signed-off-by: Miek Gieben <miek@miek.nl> * Compilez Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'test')
-rw-r--r--test/auto_test.go27
-rw-r--r--test/cache_test.go15
-rw-r--r--test/ds_file_test.go9
-rw-r--r--test/etcd_cache_test.go12
-rw-r--r--test/etcd_test.go11
-rw-r--r--test/example_test.go1
-rw-r--r--test/file_cname_proxy_test.go27
-rw-r--r--test/file_reload_test.go12
-rw-r--r--test/file_srv_additional_test.go11
-rw-r--r--test/hosts_file_test.go11
-rw-r--r--test/proxy_health_test.go27
-rw-r--r--test/proxy_http_health_test.go86
-rw-r--r--test/proxy_test.go52
-rw-r--r--test/reverse_test.go10
-rw-r--r--test/secondary_test.go9
-rw-r--r--test/wildcard_test.go13
16 files changed, 65 insertions, 268 deletions
diff --git a/test/auto_test.go b/test/auto_test.go
index c45aed4fa..9380ea78a 100644
--- a/test/auto_test.go
+++ b/test/auto_test.go
@@ -7,10 +7,6 @@ import (
"testing"
"time"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
-
"github.com/miekg/dns"
)
@@ -34,10 +30,9 @@ func TestAuto(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "www.example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("www.example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
@@ -52,7 +47,7 @@ func TestAuto(t *testing.T) {
time.Sleep(1500 * time.Millisecond) // wait for it to be picked up
- resp, err = p.Lookup(state, "www.example.org.", dns.TypeA)
+ resp, err = dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
@@ -64,7 +59,7 @@ func TestAuto(t *testing.T) {
os.Remove(filepath.Join(tmpdir, "db.example.org"))
time.Sleep(1100 * time.Millisecond) // wait for it to be picked up
- resp, err = p.Lookup(state, "www.example.org.", dns.TypeA)
+ resp, err = dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
@@ -99,10 +94,9 @@ func TestAutoNonExistentZone(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
@@ -145,12 +139,9 @@ func TestAutoAXFR(t *testing.T) {
time.Sleep(1100 * time.Millisecond) // wait for it to be picked up
- p := proxy.NewLookup([]string{udp})
m := new(dns.Msg)
m.SetAxfr("example.org.")
- state := request.Request{W: &test.ResponseWriter{}, Req: m}
-
- resp, err := p.Lookup(state, "example.org.", dns.TypeAXFR)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
diff --git a/test/cache_test.go b/test/cache_test.go
index 30f119839..1bb600492 100644
--- a/test/cache_test.go
+++ b/test/cache_test.go
@@ -3,9 +3,7 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@@ -40,21 +38,20 @@ func TestLookupCache(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
t.Run("Long TTL", func(t *testing.T) {
- testCase(t, state, p, "example.org.", 2, 10)
+ testCase(t, "example.org.", udp, 2, 10)
})
t.Run("Short TTL", func(t *testing.T) {
- testCase(t, state, p, "short.example.org.", 1, 5)
+ testCase(t, "short.example.org.", udp, 1, 5)
})
}
-func testCase(t *testing.T, state request.Request, p proxy.Proxy, name string, expectAnsLen int, expectTTL uint32) {
- resp, err := p.Lookup(state, name, dns.TypeA)
+func testCase(t *testing.T, name, addr string, expectAnsLen int, expectTTL uint32) {
+ m := new(dns.Msg)
+ m.SetQuestion(name, dns.TypeA)
+ resp, err := dns.Exchange(m, addr)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
diff --git a/test/ds_file_test.go b/test/ds_file_test.go
index 2b2be5795..c0843e98e 100644
--- a/test/ds_file_test.go
+++ b/test/ds_file_test.go
@@ -3,9 +3,7 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
mtest "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@@ -47,11 +45,10 @@ func TestLookupDS(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &mtest.ResponseWriter{}, Req: new(dns.Msg)}
-
for _, tc := range dsTestCases {
- resp, err := p.Lookup(state, tc.Qname, tc.Qtype)
+ m := new(dns.Msg)
+ m.SetQuestion(tc.Qname, tc.Qtype)
+ resp, err := dns.Exchange(m, udp)
if err != nil || resp == nil {
t.Fatalf("Expected to receive reply, but didn't for %s %d", tc.Qname, tc.Qtype)
}
diff --git a/test/etcd_cache_test.go b/test/etcd_cache_test.go
index df670e107..eb4774a8c 100644
--- a/test/etcd_cache_test.go
+++ b/test/etcd_cache_test.go
@@ -7,9 +7,6 @@ import (
"testing"
"github.com/coredns/coredns/plugin/etcd/msg"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@@ -38,16 +35,15 @@ func TestEtcdCache(t *testing.T) {
defer delete(ctx, t, etc, serv.Key)
}
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "b.example.skydns.test.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("b.example.skydns.test.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Errorf("Expected to receive reply, but didn't: %s", err)
}
checkResponse(t, resp)
- resp, err = p.Lookup(state, "b.example.skydns.test.", dns.TypeA)
+ resp, err = dns.Exchange(m, udp)
if err != nil {
t.Errorf("Expected to receive reply, but didn't: %s", err)
}
diff --git a/test/etcd_test.go b/test/etcd_test.go
index 134b2e63b..2b90c3a6c 100644
--- a/test/etcd_test.go
+++ b/test/etcd_test.go
@@ -10,9 +10,6 @@ import (
"github.com/coredns/coredns/plugin/etcd"
"github.com/coredns/coredns/plugin/etcd/msg"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
etcdcv3 "github.com/coreos/etcd/clientv3"
"github.com/miekg/dns"
@@ -38,7 +35,7 @@ func TestEtcdStubAndProxyLookup(t *testing.T) {
stubzones
path /skydns
endpoint http://localhost:2379
- upstream 8.8.8.8:53 8.8.4.4:53
+ upstream
fallthrough
}
proxy . 8.8.8.8:53
@@ -58,9 +55,9 @@ func TestEtcdStubAndProxyLookup(t *testing.T) {
defer delete(ctx, t, etc, serv.Key)
}
- p := proxy.NewLookup([]string{udp}) // use udp port from the server
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
- resp, err := p.Lookup(state, "example.com.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("example.com.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatalf("Expected to receive reply, but didn't: %v", err)
}
diff --git a/test/example_test.go b/test/example_test.go
index 484cc67d7..852143fe8 100644
--- a/test/example_test.go
+++ b/test/example_test.go
@@ -11,6 +11,5 @@ short.example.org. 1 IN A 127.0.0.3
*.w.example.org. IN TXT "Wildcard"
a.b.c.w.example.org. IN TXT "Not a wildcard"
cname.example.org. IN CNAME www.example.net.
-
service.example.org. IN SRV 8080 10 10 example.org.
`
diff --git a/test/file_cname_proxy_test.go b/test/file_cname_proxy_test.go
index 6d086e091..e6f41ee97 100644
--- a/test/file_cname_proxy_test.go
+++ b/test/file_cname_proxy_test.go
@@ -3,10 +3,6 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
-
"github.com/miekg/dns"
)
@@ -30,10 +26,9 @@ func TestZoneExternalCNAMELookupWithoutProxy(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "cname.example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("cname.example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatalf("Expected to receive reply, but didn't: %s", err)
}
@@ -52,11 +47,12 @@ func TestZoneExternalCNAMELookupWithProxy(t *testing.T) {
}
defer rm()
- // Corefile with for example without proxy section.
- corefile := `example.org:0 {
- file ` + name + ` {
- upstream 8.8.8.8
+ // Corefile with for example proxy section.
+ corefile := `.:0 {
+ file ` + name + ` example.org {
+ upstream
}
+ proxy . 8.8.8.8 8.8.4.4
}
`
i, udp, _, err := CoreDNSServerAndPorts(corefile)
@@ -65,10 +61,9 @@ func TestZoneExternalCNAMELookupWithProxy(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "cname.example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("cname.example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatalf("Expected to receive reply, but didn't: %s", err)
}
diff --git a/test/file_reload_test.go b/test/file_reload_test.go
index 2f07d9a8e..b0d6c6656 100644
--- a/test/file_reload_test.go
+++ b/test/file_reload_test.go
@@ -6,9 +6,6 @@ import (
"time"
"github.com/coredns/coredns/plugin/file"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@@ -39,10 +36,9 @@ example.net:0 {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatalf("Expected to receive reply, but didn't: %s", err)
}
@@ -55,7 +51,7 @@ example.net:0 {
time.Sleep(2 * time.Second) // reload time
- resp, err = p.Lookup(state, "example.org.", dns.TypeA)
+ resp, err = dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
diff --git a/test/file_srv_additional_test.go b/test/file_srv_additional_test.go
index 106ae7faa..9ac74d8a3 100644
--- a/test/file_srv_additional_test.go
+++ b/test/file_srv_additional_test.go
@@ -3,10 +3,6 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
-
"github.com/miekg/dns"
)
@@ -30,10 +26,9 @@ func TestZoneSRVAdditional(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "service.example.org.", dns.TypeSRV)
+ m := new(dns.Msg)
+ m.SetQuestion("service.example.org.", dns.TypeSRV)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatalf("Expected to receive reply, but didn't: %s", err)
}
diff --git a/test/hosts_file_test.go b/test/hosts_file_test.go
index 8e017aafa..b0e2ae23b 100644
--- a/test/hosts_file_test.go
+++ b/test/hosts_file_test.go
@@ -3,10 +3,6 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
-
"github.com/miekg/dns"
)
@@ -24,10 +20,9 @@ func TestHostsInlineLookup(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
diff --git a/test/proxy_health_test.go b/test/proxy_health_test.go
index 11ae1a4ee..620d8b274 100644
--- a/test/proxy_health_test.go
+++ b/test/proxy_health_test.go
@@ -3,36 +3,9 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
-
"github.com/miekg/dns"
)
-func TestProxyErratic(t *testing.T) {
- corefile := `example.org:0 {
- erratic {
- drop 2
- }
- }
-`
-
- backend, udp, _, err := CoreDNSServerAndPorts(corefile)
- if err != nil {
- t.Fatalf("Could not get CoreDNS serving instance: %s", err)
- }
- defer backend.Stop()
-
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- // We do one lookup that should not time out.
- // After this the backend is marked unhealthy anyway. So basically this
- // tests that it times out.
- p.Lookup(state, "example.org.", dns.TypeA)
-}
-
func TestProxyThreeWay(t *testing.T) {
// Run 3 CoreDNS server, 2 upstream ones and a proxy. 1 Upstream is unhealthy after 1 query, but after
// that we should still be able to send to the other one.
diff --git a/test/proxy_http_health_test.go b/test/proxy_http_health_test.go
deleted file mode 100644
index bda5a0f90..000000000
--- a/test/proxy_http_health_test.go
+++ /dev/null
@@ -1,86 +0,0 @@
-package test
-
-import (
- "io"
- "net"
- "net/http"
- "net/http/httptest"
- "net/url"
- "testing"
-
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
- "github.com/miekg/dns"
-)
-
-func TestProxyWithHTTPCheckOK(t *testing.T) {
- healthCheckServer := httptest.NewServer(http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(http.StatusOK)
- io.WriteString(w, "OK\n")
- }))
- defer healthCheckServer.Close()
-
- healthCheckURL, err := url.Parse(healthCheckServer.URL)
- if err != nil {
- t.Fatal(err)
- }
- // TODO: use URL.Port() (Go 1.8+) once we've deprecated Go 1.7 support
- var healthCheckPort string
- if _, healthCheckPort, err = net.SplitHostPort(healthCheckURL.Host); err != nil {
- healthCheckPort = "80"
- }
-
- name, rm, err := test.TempFile(".", exampleOrg)
- if err != nil {
- t.Fatalf("Failed to create zone: %s", err)
- }
- defer rm()
-
- // We have to bind to 127.0.0.1 because the server started by
- // httptest.NewServer does, and the IP addresses of the backend
- // DNS and HTTP servers must match.
- authoritativeCorefile := `example.org:0 {
- bind 127.0.0.1
- file ` + name + `
-}
-`
-
- authoritativeInstance, authoritativeAddr, _, err := CoreDNSServerAndPorts(authoritativeCorefile)
- if err != nil {
- t.Fatalf("Could not get CoreDNS authoritative instance: %s", err)
- }
- defer authoritativeInstance.Stop()
-
- proxyCorefile := `example.org:0 {
- proxy . ` + authoritativeAddr + ` {
- health_check /health:` + healthCheckPort + ` 1s
-
- }
-}
-`
-
- proxyInstance, proxyAddr, _, err := CoreDNSServerAndPorts(proxyCorefile)
- if err != nil {
- t.Fatalf("Could not get CoreDNS proxy instance: %s", err)
- }
- defer proxyInstance.Stop()
-
- p := proxy.NewLookup([]string{proxyAddr})
- 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")
- }
- // expect answer section with A record in it
- if len(resp.Answer) == 0 {
- t.Fatalf("Expected to at least one RR in the answer section, got none: %s", resp)
- }
- if resp.Answer[0].Header().Rrtype != dns.TypeA {
- t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
- }
- if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" {
- t.Errorf("Expected 127.0.0.1, got: %s", resp.Answer[0].(*dns.A).A.String())
- }
-}
diff --git a/test/proxy_test.go b/test/proxy_test.go
index 87a05a21e..50e5dae46 100644
--- a/test/proxy_test.go
+++ b/test/proxy_test.go
@@ -3,9 +3,7 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@@ -29,46 +27,9 @@ func TestLookupProxy(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- 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")
- }
- // expect answer section with A record in it
- if len(resp.Answer) == 0 {
- t.Fatalf("Expected to at least one RR in the answer section, got none: %s", resp)
- }
- if resp.Answer[0].Header().Rrtype != dns.TypeA {
- t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
- }
- if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" {
- t.Errorf("Expected 127.0.0.1, got: %s", resp.Answer[0].(*dns.A).A.String())
- }
-}
-
-func TestLookupDnsWithForcedTcp(t *testing.T) {
- t.Parallel()
- name, rm, err := test.TempFile(".", exampleOrg)
- if err != nil {
- t.Fatalf("Failed to create zone: %s", err)
- }
- defer rm()
-
- corefile := `example.org:0 {
- file ` + name + `
-}
-`
-
- i, _, tcp, err := CoreDNSServerAndPorts(corefile)
- if err != nil {
- t.Fatalf("Could not get CoreDNS serving instance: %s", err)
- }
- defer i.Stop()
-
- p := proxy.NewLookupWithOption([]string{tcp}, proxy.Options{ForceTCP: true})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
- resp, err := p.Lookup(state, "example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
@@ -108,13 +69,12 @@ func BenchmarkProxyLookup(b *testing.B) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
+ m := new(dns.Msg)
+ m.SetQuestion("example.org.", dns.TypeA)
b.ResetTimer()
for i := 0; i < b.N; i++ {
- _, err := p.Lookup(state, "example.org.", dns.TypeA)
- if err != nil {
+ if _, err := dns.Exchange(m, udp); err != nil {
b.Fatal("Expected to receive reply, but didn't")
}
}
diff --git a/test/reverse_test.go b/test/reverse_test.go
index 962601a28..f77891172 100644
--- a/test/reverse_test.go
+++ b/test/reverse_test.go
@@ -3,10 +3,6 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
- "github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
-
"github.com/miekg/dns"
)
@@ -26,9 +22,9 @@ func TestReverseCorefile(t *testing.T) {
t.Fatalf("Could not get UDP listening port")
}
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
- resp, err := p.Lookup(state, "17.0.0.10.in-addr.arpa.", dns.TypePTR)
+ m := new(dns.Msg)
+ m.SetQuestion("17.0.0.10.in-addr.arpa.", dns.TypePTR)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
diff --git a/test/secondary_test.go b/test/secondary_test.go
index 18bfd8f15..bb013bbaf 100644
--- a/test/secondary_test.go
+++ b/test/secondary_test.go
@@ -3,9 +3,7 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@@ -25,10 +23,9 @@ func TestEmptySecondaryZone(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
- resp, err := p.Lookup(state, "www.example.org.", dns.TypeA)
+ m := new(dns.Msg)
+ m.SetQuestion("www.example.org.", dns.TypeA)
+ resp, err := dns.Exchange(m, udp)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
diff --git a/test/wildcard_test.go b/test/wildcard_test.go
index b04affe6b..60e019e83 100644
--- a/test/wildcard_test.go
+++ b/test/wildcard_test.go
@@ -3,9 +3,7 @@ package test
import (
"testing"
- "github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/plugin/test"
- "github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
@@ -29,11 +27,10 @@ func TestLookupWildcard(t *testing.T) {
}
defer i.Stop()
- p := proxy.NewLookup([]string{udp})
- state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
-
for _, lookup := range []string{"a.w.example.org.", "a.a.w.example.org."} {
- resp, err := p.Lookup(state, lookup, dns.TypeTXT)
+ m := new(dns.Msg)
+ m.SetQuestion(lookup, dns.TypeTXT)
+ resp, err := dns.Exchange(m, udp)
if err != nil || resp == nil {
t.Fatalf("Expected to receive reply, but didn't for %s", lookup)
}
@@ -64,7 +61,9 @@ func TestLookupWildcard(t *testing.T) {
}
for _, lookup := range []string{"w.example.org.", "a.w.example.org.", "a.a.w.example.org."} {
- resp, err := p.Lookup(state, lookup, dns.TypeSRV)
+ m := new(dns.Msg)
+ m.SetQuestion(lookup, dns.TypeSRV)
+ resp, err := dns.Exchange(m, udp)
if err != nil || resp == nil {
t.Fatal("Expected to receive reply, but didn't", lookup)
}