示例#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,
	}
}
示例#2
0
文件: reqres.go 项目: yarpc/yarpc-go
// 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}
}