Codebase list dnss / c701ad1
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
2 changed file(s) with 15 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
9696 }
9797
9898 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()
111106 }
112107
113108 func handleTestDNS(w dns.ResponseWriter, r *dns.Msg) {
142142 panic(err)
143143 }
144144
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
145153 // TestTrace implements the tracer.Trace interface, but prints using the test
146154 // logging infrastructure.
147155 type TestTrace struct {