mirror of
https://github.com/coredns/coredns.git
synced 2025-10-29 09:14:17 -04:00
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.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user