Skip to content

Commit

Permalink
Fix XFR tests (#1188)
Browse files Browse the repository at this point in the history
* Fix XFR tests

axfrTestingSuite returned the test function that was never actually
executed. These were broken from the beginning awkwardly, though the
test cases pass fine once fixed.

* Switch axfrTestingSuite argument order

*testing.T is customarily the first argument.
  • Loading branch information
tmthrgd committed Oct 24, 2020
1 parent 93945c2 commit a3ad444
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions xfr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestSingleEnvelopeXfr(t *testing.T) {
}
defer s.Shutdown()

axfrTestingSuite(addrstr)
axfrTestingSuite(t, addrstr)
}

func TestMultiEnvelopeXfr(t *testing.T) {
Expand All @@ -97,7 +97,7 @@ func TestMultiEnvelopeXfr(t *testing.T) {
}
defer s.Shutdown()

axfrTestingSuite(addrstr)
axfrTestingSuite(t, addrstr)
}

func RunLocalTCPServerWithTsig(laddr string, tsig map[string]string) (*Server, string, error) {
Expand Down Expand Up @@ -131,33 +131,31 @@ func RunLocalTCPServerWithFinChanWithTsig(laddr string, tsig map[string]string)
return server, l.Addr().String(), fin, nil
}

func axfrTestingSuite(addrstr string) func(*testing.T) {
return func(t *testing.T) {
tr := new(Transfer)
m := new(Msg)
m.SetAxfr("miek.nl.")
func axfrTestingSuite(t *testing.T, addrstr string) {
tr := new(Transfer)
m := new(Msg)
m.SetAxfr("miek.nl.")

c, err := tr.In(m, addrstr)
if err != nil {
t.Fatal("failed to zone transfer in", err)
}
c, err := tr.In(m, addrstr)
if err != nil {
t.Fatal("failed to zone transfer in", err)
}

var records []RR
for msg := range c {
if msg.Error != nil {
t.Fatal(msg.Error)
}
records = append(records, msg.RR...)
var records []RR
for msg := range c {
if msg.Error != nil {
t.Fatal(msg.Error)
}
records = append(records, msg.RR...)
}

if len(records) != len(xfrTestData) {
t.Fatalf("bad axfr: expected %v, got %v", records, xfrTestData)
}
if len(records) != len(xfrTestData) {
t.Fatalf("bad axfr: expected %v, got %v", records, xfrTestData)
}

for i := range records {
if !IsDuplicate(records[i], xfrTestData[i]) {
t.Fatalf("bad axfr: expected %v, got %v", records, xfrTestData)
}
for i, rr := range records {
if !IsDuplicate(rr, xfrTestData[i]) {
t.Fatalf("bad axfr: expected %v, got %v", records, xfrTestData)
}
}
}

0 comments on commit a3ad444

Please sign in to comment.