test: Move zone/RR parsing to testutil
Future patches will re-use the parsing of zone/RR, so move it to testutil.
While at it, simplify the code to use RR as we never take advantage of
the full zone parsing in practice.
Alberto Bertogli
6 years ago
96 | 96 |
}
|
97 | 97 |
|
98 | 98 |
func addAnswers(tb testing.TB, zone string) {
|
99 | |
for x := range dns.ParseZone(strings.NewReader(zone), "", "") {
|
100 | |
if x.Error != nil {
|
101 | |
tb.Fatalf("error parsing zone: %v\n", x.Error)
|
102 | |
return
|
103 | |
}
|
104 | |
|
105 | |
hdr := x.RR.Header()
|
106 | |
key := fmt.Sprintf("%s %d", hdr.Name, hdr.Rrtype)
|
107 | |
answersMu.Lock()
|
108 | |
answers[key] = append(answers[key], x.RR)
|
109 | |
answersMu.Unlock()
|
110 | |
}
|
|
99 |
rr := testutil.NewRR(tb, zone)
|
|
100 |
hdr := rr.Header()
|
|
101 |
key := fmt.Sprintf("%s %d", hdr.Name, hdr.Rrtype)
|
|
102 |
|
|
103 |
answersMu.Lock()
|
|
104 |
answers[key] = append(answers[key], rr)
|
|
105 |
answersMu.Unlock()
|
111 | 106 |
}
|
112 | 107 |
|
113 | 108 |
func handleTestDNS(w dns.ResponseWriter, r *dns.Msg) {
|
142 | 142 |
panic(err)
|
143 | 143 |
}
|
144 | 144 |
|
|
145 |
func NewRR(tb testing.TB, s string) dns.RR {
|
|
146 |
rr, err := dns.NewRR(s)
|
|
147 |
if err != nil {
|
|
148 |
tb.Fatalf("Error parsing RR for testing: %v", err)
|
|
149 |
}
|
|
150 |
return rr
|
|
151 |
}
|
|
152 |
|
145 | 153 |
// TestTrace implements the tracer.Trace interface, but prints using the test
|
146 | 154 |
// logging infrastructure.
|
147 | 155 |
type TestTrace struct {
|