Commit 7f46df6d authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

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.
parent 65b56248
...@@ -56,6 +56,8 @@ func TestAutoPath(t *testing.T) { ...@@ -56,6 +56,8 @@ func TestAutoPath(t *testing.T) {
continue continue
} }
// No sorting here as we want to check if the CNAME sits *before* the
// test of the answer.
resp := rec.Msg resp := rec.Msg
if !test.Header(t, tc, resp) { if !test.Header(t, tc, resp) {
......
package dnssec package dnssec
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -104,23 +103,7 @@ func TestLookupZone(t *testing.T) { ...@@ -104,23 +103,7 @@ func TestLookupZone(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
...@@ -147,23 +130,7 @@ func TestLookupDNSKEY(t *testing.T) { ...@@ -147,23 +130,7 @@ func TestLookupDNSKEY(t *testing.T) {
t.Errorf("Authoritative Answer should be true, got false") t.Errorf("Authoritative Answer should be true, got false")
} }
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
package etcd package etcd
import ( import (
"sort"
"testing" "testing"
"github.com/coredns/coredns/middleware/etcd/msg" "github.com/coredns/coredns/middleware/etcd/msg"
...@@ -29,23 +28,7 @@ func TestDebugLookup(t *testing.T) { ...@@ -29,23 +28,7 @@ func TestDebugLookup(t *testing.T) {
etc.ServeDNS(ctxt, rec, m) etc.ServeDNS(ctxt, rec, m)
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
...@@ -63,23 +46,7 @@ func TestDebugLookupFalse(t *testing.T) { ...@@ -63,23 +46,7 @@ func TestDebugLookupFalse(t *testing.T) {
etc.ServeDNS(ctxt, rec, m) etc.ServeDNS(ctxt, rec, m)
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
package etcd package etcd
import ( import (
"sort"
"testing" "testing"
"github.com/coredns/coredns/middleware/etcd/msg" "github.com/coredns/coredns/middleware/etcd/msg"
...@@ -31,23 +30,7 @@ func TestGroupLookup(t *testing.T) { ...@@ -31,23 +30,7 @@ func TestGroupLookup(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
...@@ -5,7 +5,6 @@ package etcd ...@@ -5,7 +5,6 @@ package etcd
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"sort"
"testing" "testing"
"time" "time"
...@@ -267,23 +266,7 @@ func TestLookup(t *testing.T) { ...@@ -267,23 +266,7 @@ func TestLookup(t *testing.T) {
etc.ServeDNS(ctxt, rec, m) etc.ServeDNS(ctxt, rec, m)
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
package etcd package etcd
import ( import (
"sort"
"testing" "testing"
"github.com/coredns/coredns/middleware/etcd/msg" "github.com/coredns/coredns/middleware/etcd/msg"
...@@ -34,23 +33,7 @@ func TestMultiLookup(t *testing.T) { ...@@ -34,23 +33,7 @@ func TestMultiLookup(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
...@@ -6,7 +6,6 @@ package etcd ...@@ -6,7 +6,6 @@ package etcd
import ( import (
"fmt" "fmt"
"sort"
"strings" "strings"
"testing" "testing"
...@@ -35,23 +34,7 @@ func TestOtherLookup(t *testing.T) { ...@@ -35,23 +34,7 @@ func TestOtherLookup(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
package etcd package etcd
import ( import (
"sort"
"testing" "testing"
"github.com/coredns/coredns/middleware/etcd/msg" "github.com/coredns/coredns/middleware/etcd/msg"
...@@ -35,23 +34,7 @@ func TestProxyLookupFailDebug(t *testing.T) { ...@@ -35,23 +34,7 @@ func TestProxyLookupFailDebug(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
...@@ -4,7 +4,6 @@ package etcd ...@@ -4,7 +4,6 @@ package etcd
import ( import (
"net" "net"
"sort"
"strconv" "strconv"
"testing" "testing"
...@@ -66,23 +65,8 @@ func TestStubLookup(t *testing.T) { ...@@ -66,23 +65,8 @@ func TestStubLookup(t *testing.T) {
// etcd not running? // etcd not running?
continue 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) { test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -34,25 +33,7 @@ func TestLookupCNAMEChain(t *testing.T) { ...@@ -34,25 +33,7 @@ func TestLookupCNAMEChain(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
...@@ -109,25 +90,7 @@ func TestLookupCNAMEExternal(t *testing.T) { ...@@ -109,25 +90,7 @@ func TestLookupCNAMEExternal(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -171,23 +170,7 @@ func testDelegation(t *testing.T, z, origin string, testcases []test.Case) { ...@@ -171,23 +170,7 @@ func testDelegation(t *testing.T, z, origin string, testcases []test.Case) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -110,23 +109,7 @@ func TestLookupDNAME(t *testing.T) { ...@@ -110,23 +109,7 @@ func TestLookupDNAME(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
...@@ -179,23 +162,7 @@ func TestLookupDNAMEDNSSEC(t *testing.T) { ...@@ -179,23 +162,7 @@ func TestLookupDNAMEDNSSEC(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -147,25 +146,7 @@ func TestLookupDNSSEC(t *testing.T) { ...@@ -147,25 +146,7 @@ func TestLookupDNSSEC(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -71,22 +70,6 @@ func TestLookupDS(t *testing.T) { ...@@ -71,22 +70,6 @@ func TestLookupDS(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -51,25 +50,7 @@ func TestLookupEnt(t *testing.T) { ...@@ -51,25 +50,7 @@ func TestLookupEnt(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -53,25 +52,7 @@ func TestLookupGlue(t *testing.T) { ...@@ -53,25 +52,7 @@ func TestLookupGlue(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -123,25 +122,7 @@ func TestLookup(t *testing.T) { ...@@ -123,25 +122,7 @@ func TestLookup(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package file package file
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
...@@ -98,23 +97,7 @@ func TestLookupWildcard(t *testing.T) { ...@@ -98,23 +97,7 @@ func TestLookupWildcard(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
...@@ -175,23 +158,7 @@ func TestLookupDoubleWildcard(t *testing.T) { ...@@ -175,23 +158,7 @@ func TestLookupDoubleWildcard(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
...@@ -246,23 +213,7 @@ func TestLookupApexWildcard(t *testing.T) { ...@@ -246,23 +213,7 @@ func TestLookupApexWildcard(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
...@@ -305,23 +256,7 @@ func TestLookupMultiWildcard(t *testing.T) { ...@@ -305,23 +256,7 @@ func TestLookupMultiWildcard(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package hosts package hosts
import ( import (
"sort"
"strings" "strings"
"testing" "testing"
"time" "time"
...@@ -30,25 +29,7 @@ func TestLookupA(t *testing.T) { ...@@ -30,25 +29,7 @@ func TestLookupA(t *testing.T) {
} }
resp := rec.Msg resp := rec.Msg
sort.Sort(test.RRSet(resp.Answer)) test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package kubernetes package kubernetes
import ( import (
"sort"
"testing" "testing"
"github.com/coredns/coredns/middleware/pkg/dnsrecorder" "github.com/coredns/coredns/middleware/pkg/dnsrecorder"
...@@ -201,24 +200,7 @@ func runServeDNSTests(ctx context.Context, t *testing.T, dnsTestCases map[string ...@@ -201,24 +200,7 @@ func runServeDNSTests(ctx context.Context, t *testing.T, dnsTestCases map[string
} }
} }
test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
......
package kubernetes package kubernetes
import ( import (
"sort"
"testing" "testing"
"github.com/coredns/coredns/middleware/pkg/dnsrecorder" "github.com/coredns/coredns/middleware/pkg/dnsrecorder"
...@@ -118,23 +117,6 @@ func TestReverse(t *testing.T) { ...@@ -118,23 +117,6 @@ func TestReverse(t *testing.T) {
if resp == nil { 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) t.Fatalf("Test %d: got nil message and no error for: %s %d", i, r.Question[0].Name, r.Question[0].Qtype)
} }
test.SortAndCheck(t, resp, tc)
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)
}
} }
} }
package test package test
import ( import (
"sort"
"testing" "testing"
"github.com/miekg/dns" "github.com/miekg/dns"
...@@ -263,6 +264,33 @@ func Section(t *testing.T, tc Case, sec sect, rr []dns.RR) bool { ...@@ -263,6 +264,33 @@ func Section(t *testing.T, tc Case, sec sect, rr []dns.RR) bool {
return true 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. // ErrorHandler returns a Handler that returns ServerFailure error when called.
func ErrorHandler() Handler { func ErrorHandler() Handler {
return HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { return HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
......
package test
import "testing"
func TestA(t *testing.T) {
// should not crash
A("miek.nl. IN A 127.0.0.1")
}
...@@ -3,7 +3,6 @@ package test ...@@ -3,7 +3,6 @@ package test
import ( import (
"io/ioutil" "io/ioutil"
"log" "log"
"sort"
"testing" "testing"
"github.com/coredns/coredns/middleware/proxy" "github.com/coredns/coredns/middleware/proxy"
...@@ -66,22 +65,6 @@ func TestLookupDS(t *testing.T) { ...@@ -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) t.Fatalf("Expected to receive reply, but didn't for %s %d", tc.Qname, tc.Qtype)
} }
sort.Sort(mtest.RRSet(resp.Answer)) mtest.SortAndCheck(t, resp, tc)
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)
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment