Пример #1
0
func queryA(t *testing.T, c *cachingResolver, rr, domain, expected string) *dns.Msg {
	// Set up the response from the given RR (if any).
	if rr != "" {
		back := c.back.(*TestResolver)
		back.response = newReply(mustNewRR(t, rr))
	}

	tr := util.NewTestTrace(t)
	defer tr.Finish()

	req := newQuery(domain, dns.TypeA)
	resp, err := c.Query(req, tr)
	if err != nil {
		t.Fatalf("query failed: %v", err)
	}

	a := resp.Answer[0].(*dns.A)
	if a.A.String() != expected {
		t.Errorf("expected %s, got %v", expected, a.A)
	}

	if !reflect.DeepEqual(req.Question, resp.Question) {
		t.Errorf("question mis-match: request %v, response %v",
			req.Question, resp.Question)
	}

	return resp
}
Пример #2
0
func queryFail(t *testing.T, c *cachingResolver) *dns.Msg {
	back := c.back.(*TestResolver)
	back.response = &dns.Msg{}
	back.response.Response = true
	back.response.Rcode = dns.RcodeNameError

	tr := util.NewTestTrace(t)
	defer tr.Finish()

	req := newQuery("doesnotexist.", dns.TypeA)
	resp, err := c.Query(req, tr)
	if err != nil {
		t.Fatalf("query failed: %v", err)
	}

	return resp
}