author | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-04-15 13:22:18 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-04-15 13:22:18 UTC |
parent | 207b26bb7b92ab009e62731e398ea1fb0ee794fd |
dnss_test.go | +6 | -11 |
internal/testutil/testutil.go | +8 | -0 |
diff --git a/dnss_test.go b/dnss_test.go index eb2e66d..5150ed0 100644 --- a/dnss_test.go +++ b/dnss_test.go @@ -97,18 +97,13 @@ func resetAnswers() { } func addAnswers(tb testing.TB, zone string) { - for x := range dns.ParseZone(strings.NewReader(zone), "", "") { - if x.Error != nil { - tb.Fatalf("error parsing zone: %v\n", x.Error) - return - } + rr := testutil.NewRR(tb, zone) + hdr := rr.Header() + key := fmt.Sprintf("%s %d", hdr.Name, hdr.Rrtype) - hdr := x.RR.Header() - key := fmt.Sprintf("%s %d", hdr.Name, hdr.Rrtype) - answersMu.Lock() - answers[key] = append(answers[key], x.RR) - answersMu.Unlock() - } + answersMu.Lock() + answers[key] = append(answers[key], rr) + answersMu.Unlock() } func handleTestDNS(w dns.ResponseWriter, r *dns.Msg) { diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go index 4737911..98e884f 100644 --- a/internal/testutil/testutil.go +++ b/internal/testutil/testutil.go @@ -143,6 +143,14 @@ func ServeTestDNSServer(addr string, handler func(dns.ResponseWriter, *dns.Msg)) panic(err) } +func NewRR(tb testing.TB, s string) dns.RR { + rr, err := dns.NewRR(s) + if err != nil { + tb.Fatalf("Error parsing RR for testing: %v", err) + } + return rr +} + // TestTrace implements the tracer.Trace interface, but prints using the test // logging infrastructure. type TestTrace struct {