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:
Miek Gieben
2017-08-16 15:30:58 +01:00
committed by GitHub
parent 65b56248f0
commit 7f46df6d27
24 changed files with 58 additions and 520 deletions

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}