Ejemplo n.º 1
0
func (r *Recorder) responseToResponseRecord(response *transport.Response) responseRecord {
	responseBody, err := ioutil.ReadAll(response.Body)
	if err != nil {
		r.logger.Fatal(err)
	}
	response.Body = ioutil.NopCloser(bytes.NewReader(responseBody))
	return responseRecord{
		Headers: response.Headers.Items(),
		Body:    responseBody,
	}
}
Ejemplo n.º 2
0
// NewResponseMatcher builds a new ResponseMatcher that verifies that
// responses match the given Response.
func NewResponseMatcher(t *testing.T, r *transport.Response) ResponseMatcher {
	body, err := ioutil.ReadAll(r.Body)
	defer r.Body.Close()
	if err != nil {
		t.Fatalf("failed to read response body: %v", err)
	}

	// restore a copy of the body so that the caller can still use the
	// response object
	r.Body = ioutil.NopCloser(bytes.NewReader(body))
	return ResponseMatcher{t: t, res: r, body: body}
}