pkg: add dnstest (#1098)

Add a full test server impl in this new package + tests. Move
dnsrecorder into this package as well and finish up the commented out
tests that were left in the old dnsrecorder package.

Update all callers and tests.
This commit is contained in:
Miek Gieben
2017-09-21 15:15:47 +01:00
committed by GitHub
parent 7109c6715c
commit 284061eee7
44 changed files with 223 additions and 131 deletions

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/plugin/test"
@@ -25,7 +25,7 @@ func TestLookupCNAMEChain(t *testing.T) {
for _, tc := range cnameTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)
@@ -82,7 +82,7 @@ func TestLookupCNAMEExternal(t *testing.T) {
for _, tc := range exernalTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -162,7 +162,7 @@ func testDelegation(t *testing.T, z, origin string, testcases []test.Case) {
for _, tc := range testcases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %q\n", err)

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -101,7 +101,7 @@ func TestLookupDNAME(t *testing.T) {
for _, tc := range dnameTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)
@@ -154,7 +154,7 @@ func TestLookupDNAMEDNSSEC(t *testing.T) {
for _, tc := range dnameDnssecTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -138,7 +138,7 @@ func TestLookupDNSSEC(t *testing.T) {
for _, tc := range dnssecTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)
@@ -158,7 +158,7 @@ func BenchmarkFileLookupDNSSEC(b *testing.B) {
fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{testzone: zone}, Names: []string{testzone}}}
ctx := context.TODO()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
tc := test.Case{
Qname: "b.miek.nl.", Qtype: dns.TypeA, Do: true,

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -62,7 +62,7 @@ func TestLookupDS(t *testing.T) {
for _, tc := range dsTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -42,7 +42,7 @@ func TestLookupEnt(t *testing.T) {
for _, tc := range entTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("expected no error, got %v\n", err)

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -44,7 +44,7 @@ func TestLookupGlue(t *testing.T) {
for _, tc := range atoomTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -114,7 +114,7 @@ func TestLookup(t *testing.T) {
for _, tc := range dnsTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("expected no error, got %v\n", err)
@@ -131,7 +131,7 @@ func TestLookupNil(t *testing.T) {
ctx := context.TODO()
m := dnsTestCases[0].Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
fm.ServeDNS(ctx, rec, m)
}
@@ -143,7 +143,7 @@ func BenchmarkFileLookup(b *testing.B) {
fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{testzone: zone}, Names: []string{testzone}}}
ctx := context.TODO()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
tc := test.Case{
Qname: "www.miek.nl.", Qtype: dns.TypeA,

View File

@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/pkg/dnsrecorder"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -89,7 +89,7 @@ func TestLookupWildcard(t *testing.T) {
for _, tc := range wildcardTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)
@@ -150,7 +150,7 @@ func TestLookupDoubleWildcard(t *testing.T) {
for _, tc := range wildcardDoubleTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)
@@ -205,7 +205,7 @@ func TestLookupApexWildcard(t *testing.T) {
for _, tc := range apexWildcardTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)
@@ -248,7 +248,7 @@ func TestLookupMultiWildcard(t *testing.T) {
for _, tc := range multiWildcardTestCases {
m := tc.Msg()
rec := dnsrecorder.New(&test.ResponseWriter{})
rec := dnstest.NewRecorder(&test.ResponseWriter{})
_, err := fm.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("Expected no error, got %v\n", err)