aboutsummaryrefslogtreecommitdiff
path: root/middleware/test/helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/test/helpers.go')
-rw-r--r--middleware/test/helpers.go28
1 files changed, 28 insertions, 0 deletions
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) {