aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-08-16 15:30:58 +0100
committerGravatar GitHub <noreply@github.com> 2017-08-16 15:30:58 +0100
commit7f46df6d274eff51569b57b382480301caa1dff6 (patch)
tree4a6062700acc0bd110ef622b64f055a235042294
parent65b56248f0f4a43fe71435c4d801b94c3f168f65 (diff)
downloadcoredns-7f46df6d274eff51569b57b382480301caa1dff6.tar.gz
coredns-7f46df6d274eff51569b57b382480301caa1dff6.tar.zst
coredns-7f46df6d274eff51569b57b382480301caa1dff6.zip
tests: add SortAndCheck helper (#926)
There was quite some code duplication in a lot of tests to check if an answer was considered Ok. Created a test.SortAndCheck helper function that takes care of this.
-rw-r--r--middleware/autopath/autopath_test.go2
-rw-r--r--middleware/dnssec/handler_test.go37
-rw-r--r--middleware/etcd/debug_test.go37
-rw-r--r--middleware/etcd/group_test.go19
-rw-r--r--middleware/etcd/lookup_test.go19
-rw-r--r--middleware/etcd/multi_test.go19
-rw-r--r--middleware/etcd/other_test.go19
-rw-r--r--middleware/etcd/proxy_lookup_test.go19
-rw-r--r--middleware/etcd/stub_test.go18
-rw-r--r--middleware/file/cname_test.go41
-rw-r--r--middleware/file/delegation_test.go19
-rw-r--r--middleware/file/dname_test.go37
-rw-r--r--middleware/file/dnssec_test.go21
-rw-r--r--middleware/file/ds_test.go19
-rw-r--r--middleware/file/ent_test.go21
-rw-r--r--middleware/file/glue_test.go21
-rw-r--r--middleware/file/lookup_test.go21
-rw-r--r--middleware/file/wildcard_test.go73
-rw-r--r--middleware/hosts/hosts_test.go21
-rw-r--r--middleware/kubernetes/handler_test.go20
-rw-r--r--middleware/kubernetes/reverse_test.go20
-rw-r--r--middleware/test/helpers.go28
-rw-r--r--middleware/test/helpers_test.go8
-rw-r--r--test/ds_file_test.go19
24 files changed, 58 insertions, 520 deletions
diff --git a/middleware/autopath/autopath_test.go b/middleware/autopath/autopath_test.go
index 719389446..ca1290e26 100644
--- a/middleware/autopath/autopath_test.go
+++ b/middleware/autopath/autopath_test.go
@@ -56,6 +56,8 @@ func TestAutoPath(t *testing.T) {
continue
}
+ // No sorting here as we want to check if the CNAME sits *before* the
+ // test of the answer.
resp := rec.Msg
if !test.Header(t, tc, resp) {
diff --git a/middleware/dnssec/handler_test.go b/middleware/dnssec/handler_test.go
index 60847d17b..19d0ef01f 100644
--- a/middleware/dnssec/handler_test.go
+++ b/middleware/dnssec/handler_test.go
@@ -1,7 +1,6 @@
package dnssec
import (
- "sort"
"strings"
"testing"
@@ -104,23 +103,7 @@ func TestLookupZone(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
@@ -147,23 +130,7 @@ func TestLookupDNSKEY(t *testing.T) {
t.Errorf("Authoritative Answer should be true, got false")
}
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/etcd/debug_test.go b/middleware/etcd/debug_test.go
index 65e503d6a..ccb06fa68 100644
--- a/middleware/etcd/debug_test.go
+++ b/middleware/etcd/debug_test.go
@@ -3,7 +3,6 @@
package etcd
import (
- "sort"
"testing"
"github.com/coredns/coredns/middleware/etcd/msg"
@@ -29,23 +28,7 @@ func TestDebugLookup(t *testing.T) {
etc.ServeDNS(ctxt, rec, m)
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
@@ -63,23 +46,7 @@ func TestDebugLookupFalse(t *testing.T) {
etc.ServeDNS(ctxt, rec, m)
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/etcd/group_test.go b/middleware/etcd/group_test.go
index 0c18587ca..43ce4754a 100644
--- a/middleware/etcd/group_test.go
+++ b/middleware/etcd/group_test.go
@@ -3,7 +3,6 @@
package etcd
import (
- "sort"
"testing"
"github.com/coredns/coredns/middleware/etcd/msg"
@@ -31,23 +30,7 @@ func TestGroupLookup(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/etcd/lookup_test.go b/middleware/etcd/lookup_test.go
index 79e48648a..e2cdee15c 100644
--- a/middleware/etcd/lookup_test.go
+++ b/middleware/etcd/lookup_test.go
@@ -5,7 +5,6 @@ package etcd
import (
"context"
"encoding/json"
- "sort"
"testing"
"time"
@@ -267,23 +266,7 @@ func TestLookup(t *testing.T) {
etc.ServeDNS(ctxt, rec, m)
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/etcd/multi_test.go b/middleware/etcd/multi_test.go
index bd2432a1a..301b2c49e 100644
--- a/middleware/etcd/multi_test.go
+++ b/middleware/etcd/multi_test.go
@@ -3,7 +3,6 @@
package etcd
import (
- "sort"
"testing"
"github.com/coredns/coredns/middleware/etcd/msg"
@@ -34,23 +33,7 @@ func TestMultiLookup(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/etcd/other_test.go b/middleware/etcd/other_test.go
index 22b720078..b3849b9f7 100644
--- a/middleware/etcd/other_test.go
+++ b/middleware/etcd/other_test.go
@@ -6,7 +6,6 @@ package etcd
import (
"fmt"
- "sort"
"strings"
"testing"
@@ -35,23 +34,7 @@ func TestOtherLookup(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/etcd/proxy_lookup_test.go b/middleware/etcd/proxy_lookup_test.go
index 3ee3005d7..aa9de9281 100644
--- a/middleware/etcd/proxy_lookup_test.go
+++ b/middleware/etcd/proxy_lookup_test.go
@@ -3,7 +3,6 @@
package etcd
import (
- "sort"
"testing"
"github.com/coredns/coredns/middleware/etcd/msg"
@@ -35,23 +34,7 @@ func TestProxyLookupFailDebug(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/etcd/stub_test.go b/middleware/etcd/stub_test.go
index 2ec89c0bf..5f22f42c9 100644
--- a/middleware/etcd/stub_test.go
+++ b/middleware/etcd/stub_test.go
@@ -4,7 +4,6 @@ package etcd
import (
"net"
- "sort"
"strconv"
"testing"
@@ -66,23 +65,8 @@ func TestStubLookup(t *testing.T) {
// etcd not running?
continue
}
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/cname_test.go b/middleware/file/cname_test.go
index ff9387b29..90e6f05a9 100644
--- a/middleware/file/cname_test.go
+++ b/middleware/file/cname_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -34,25 +33,7 @@ func TestLookupCNAMEChain(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
-
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
-
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
@@ -109,25 +90,7 @@ func TestLookupCNAMEExternal(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
-
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
-
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/delegation_test.go b/middleware/file/delegation_test.go
index 925930bab..49510944f 100644
--- a/middleware/file/delegation_test.go
+++ b/middleware/file/delegation_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -171,23 +170,7 @@ func testDelegation(t *testing.T, z, origin string, testcases []test.Case) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/dname_test.go b/middleware/file/dname_test.go
index 96e42454f..27890a78c 100644
--- a/middleware/file/dname_test.go
+++ b/middleware/file/dname_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -110,23 +109,7 @@ func TestLookupDNAME(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
@@ -179,23 +162,7 @@ func TestLookupDNAMEDNSSEC(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/dnssec_test.go b/middleware/file/dnssec_test.go
index 95bc74ed1..136a9dfee 100644
--- a/middleware/file/dnssec_test.go
+++ b/middleware/file/dnssec_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -147,25 +146,7 @@ func TestLookupDNSSEC(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
-
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
-
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/ds_test.go b/middleware/file/ds_test.go
index 32ae5187a..f5c9bb332 100644
--- a/middleware/file/ds_test.go
+++ b/middleware/file/ds_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -71,22 +70,6 @@ func TestLookupDS(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/ent_test.go b/middleware/file/ent_test.go
index f8e5da4fe..433aa182d 100644
--- a/middleware/file/ent_test.go
+++ b/middleware/file/ent_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -51,25 +50,7 @@ func TestLookupEnt(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
-
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
-
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/glue_test.go b/middleware/file/glue_test.go
index 4e9cf1823..14716ae33 100644
--- a/middleware/file/glue_test.go
+++ b/middleware/file/glue_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -53,25 +52,7 @@ func TestLookupGlue(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
-
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
-
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/lookup_test.go b/middleware/file/lookup_test.go
index 9be6ae542..82d8f77ff 100644
--- a/middleware/file/lookup_test.go
+++ b/middleware/file/lookup_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -123,25 +122,7 @@ func TestLookup(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
-
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
-
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/file/wildcard_test.go b/middleware/file/wildcard_test.go
index 29a6adb33..7f1a2fed3 100644
--- a/middleware/file/wildcard_test.go
+++ b/middleware/file/wildcard_test.go
@@ -1,7 +1,6 @@
package file
import (
- "sort"
"strings"
"testing"
@@ -98,23 +97,7 @@ func TestLookupWildcard(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
@@ -175,23 +158,7 @@ func TestLookupDoubleWildcard(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
@@ -246,23 +213,7 @@ func TestLookupApexWildcard(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
@@ -305,23 +256,7 @@ func TestLookupMultiWildcard(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/hosts/hosts_test.go b/middleware/hosts/hosts_test.go
index 37716623a..b6ebaa43a 100644
--- a/middleware/hosts/hosts_test.go
+++ b/middleware/hosts/hosts_test.go
@@ -1,7 +1,6 @@
package hosts
import (
- "sort"
"strings"
"testing"
"time"
@@ -30,25 +29,7 @@ func TestLookupA(t *testing.T) {
}
resp := rec.Msg
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
-
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
-
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/kubernetes/handler_test.go b/middleware/kubernetes/handler_test.go
index b00f5382e..e8ef49999 100644
--- a/middleware/kubernetes/handler_test.go
+++ b/middleware/kubernetes/handler_test.go
@@ -1,7 +1,6 @@
package kubernetes
import (
- "sort"
"testing"
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
@@ -201,24 +200,7 @@ func runServeDNSTests(ctx context.Context, t *testing.T, dnsTestCases map[string
}
}
-
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("%v Received:\n %v\n", testname, resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("%v Received:\n %v\n", testname, resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("%v Received:\n %v\n", testname, resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("%v Received:\n %v\n", testname, resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/kubernetes/reverse_test.go b/middleware/kubernetes/reverse_test.go
index 4de3e0a96..7cc51da17 100644
--- a/middleware/kubernetes/reverse_test.go
+++ b/middleware/kubernetes/reverse_test.go
@@ -1,7 +1,6 @@
package kubernetes
import (
- "sort"
"testing"
"github.com/coredns/coredns/middleware/pkg/dnsrecorder"
@@ -118,23 +117,6 @@ func TestReverse(t *testing.T) {
if resp == nil {
t.Fatalf("Test %d: got nil message and no error for: %s %d", i, r.Question[0].Name, r.Question[0].Qtype)
}
-
- sort.Sort(test.RRSet(resp.Answer))
- sort.Sort(test.RRSet(resp.Ns))
- sort.Sort(test.RRSet(resp.Extra))
-
- if !test.Header(t, tc, resp) {
- t.Logf("Test %d, received: %v", i, resp)
- continue
- }
- if !test.Section(t, tc, test.Answer, resp.Answer) {
- t.Logf("Test %d, received: %v", i, resp)
- }
- if !test.Section(t, tc, test.Ns, resp.Ns) {
- t.Logf("Test %d, received: %v", i, resp)
- }
- if !test.Section(t, tc, test.Extra, resp.Extra) {
- t.Logf("Test %d, received: %v", i, resp)
- }
+ test.SortAndCheck(t, resp, tc)
}
}
diff --git a/middleware/test/helpers.go b/middleware/test/helpers.go
index 613025f26..8d9cada43 100644
--- a/middleware/test/helpers.go
+++ b/middleware/test/helpers.go
@@ -1,6 +1,7 @@
package test
import (
+ "sort"
"testing"
"github.com/miekg/dns"
@@ -263,6 +264,33 @@ func Section(t *testing.T, tc Case, sec sect, rr []dns.RR) bool {
return true
}
+// SortAndCheck sorts resp and the checks the header and three sections against the testcase in tc.
+func SortAndCheck(t *testing.T, resp *dns.Msg, tc Case) {
+ sort.Sort(RRSet(resp.Answer))
+ sort.Sort(RRSet(resp.Ns))
+ sort.Sort(RRSet(resp.Extra))
+
+ if !Header(t, tc, resp) {
+ t.Logf("%v\n", resp)
+ return
+ }
+
+ if !Section(t, tc, Answer, resp.Answer) {
+ t.Logf("%v\n", resp)
+ return
+ }
+ if !Section(t, tc, Ns, resp.Ns) {
+ t.Logf("%v\n", resp)
+ return
+
+ }
+ if !Section(t, tc, Extra, resp.Extra) {
+ t.Logf("%v\n", resp)
+ return
+ }
+ return
+}
+
// ErrorHandler returns a Handler that returns ServerFailure error when called.
func ErrorHandler() Handler {
return HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
diff --git a/middleware/test/helpers_test.go b/middleware/test/helpers_test.go
deleted file mode 100644
index 1b4d95bbc..000000000
--- a/middleware/test/helpers_test.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package test
-
-import "testing"
-
-func TestA(t *testing.T) {
- // should not crash
- A("miek.nl. IN A 127.0.0.1")
-}
diff --git a/test/ds_file_test.go b/test/ds_file_test.go
index 16170aad3..3775c9033 100644
--- a/test/ds_file_test.go
+++ b/test/ds_file_test.go
@@ -3,7 +3,6 @@ package test
import (
"io/ioutil"
"log"
- "sort"
"testing"
"github.com/coredns/coredns/middleware/proxy"
@@ -66,22 +65,6 @@ func TestLookupDS(t *testing.T) {
t.Fatalf("Expected to receive reply, but didn't for %s %d", tc.Qname, tc.Qtype)
}
- sort.Sort(mtest.RRSet(resp.Answer))
- sort.Sort(mtest.RRSet(resp.Ns))
- sort.Sort(mtest.RRSet(resp.Extra))
-
- if !mtest.Header(t, tc, resp) {
- t.Logf("%v\n", resp)
- continue
- }
- if !mtest.Section(t, tc, mtest.Answer, resp.Answer) {
- t.Logf("%v\n", resp)
- }
- if !mtest.Section(t, tc, mtest.Ns, resp.Ns) {
- t.Logf("%v\n", resp)
- }
- if !mtest.Section(t, tc, mtest.Extra, resp.Extra) {
- t.Logf("%v\n", resp)
- }
+ mtest.SortAndCheck(t, resp, tc)
}
}