github.com/xmidt-org/webpa-common@v1.11.9/xhttp/xhttptest/response.go (about)

     1  package xhttptest
     2  
     3  import (
     4  	"bytes"
     5  	"io/ioutil"
     6  	"net/http"
     7  	"strconv"
     8  )
     9  
    10  // NewResponse provides a convenient way of synthesizing a client response, similar to httptest.NewRequest.
    11  // This function initializes most members to useful values for testing with.
    12  func NewResponse(statusCode int, body []byte) *http.Response {
    13  	return &http.Response{
    14  		Status:        strconv.Itoa(statusCode),
    15  		StatusCode:    statusCode,
    16  		Proto:         "HTTP/1.1",
    17  		ProtoMajor:    1,
    18  		ProtoMinor:    1,
    19  		Header:        make(http.Header),
    20  		Body:          ioutil.NopCloser(bytes.NewReader(body)),
    21  		ContentLength: int64(len(body)),
    22  	}
    23  }