diff options
author | 2017-08-16 15:30:58 +0100 | |
---|---|---|
committer | 2017-08-16 15:30:58 +0100 | |
commit | 7f46df6d274eff51569b57b382480301caa1dff6 (patch) | |
tree | 4a6062700acc0bd110ef622b64f055a235042294 /middleware/test/helpers.go | |
parent | 65b56248f0f4a43fe71435c4d801b94c3f168f65 (diff) | |
download | coredns-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.
Diffstat (limited to 'middleware/test/helpers.go')
-rw-r--r-- | middleware/test/helpers.go | 28 |
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) { |