本文整理汇总了Golang中github.com/stretchr/testify/http.TestResponseWriter类的典型用法代码示例。如果您正苦于以下问题:Golang TestResponseWriter类的具体用法?Golang TestResponseWriter怎么用?Golang TestResponseWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestResponseWriter类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RoundTrip
func (r inProcessRoundTripper) RoundTrip(req *http.Request) (response *http.Response, err error) {
var match mux.RouteMatch
switch handler, _ := r.mux.Handler(req); handler.(type) {
default:
err = fmt.Errorf("handler for request '%v' was not of type %v", req.RequestURI, reflect.TypeOf((*mux.Router)(nil)))
return
case *mux.Router:
if !handler.(*mux.Router).Match(req, &match) {
err = fmt.Errorf("no match found for path '%v'", req.URL)
return
}
}
responseWriter := mockHttp.TestResponseWriter{}
match.Handler.(http.HandlerFunc)(&responseWriter, req) // TODO check that it's a HandlerFunc to avoid a panic
var httpBuffer bytes.Buffer
fmt.Fprintf(&httpBuffer, "HTTP/1.1 %v\r\n", statusLine(responseWriter.WrittenHeaderInt))
responseWriter.Header().Write(&httpBuffer)
fmt.Fprintf(&httpBuffer, "\r\n%v", responseWriter.Output)
response, err = http.ReadResponse(bufio.NewReader(&httpBuffer), req)
return
}
示例2: TestRedirectTo
func TestRedirectTo(t *testing.T) {
r := new(testhttp.TestResponseWriter)
RedirectTo(r, "http://www.stretchr.com", "test")
assert.Equal(t, "http://www.stretchr.com/test", r.Header().Get("Location"))
assert.Equal(t, 0, r.StatusCode)
}
示例3: TestRedirectPerm
func TestRedirectPerm(t *testing.T) {
r := new(testhttp.TestResponseWriter)
RedirectPerm(r, "http://www.stretchr.com", "test")
assert.Equal(t, "http://www.stretchr.com/test", r.Header().Get("Location"))
assert.Equal(t, http.StatusMovedPermanently, r.WrittenHeaderInt)
}
示例4: TestRedirectTemp
func TestRedirectTemp(t *testing.T) {
r := new(testhttp.TestResponseWriter)
RedirectTemp(r, "http://www.stretchr.com", "test")
assert.Equal(t, "http://www.stretchr.com/test", r.Header().Get("Location"))
assert.Equal(t, http.StatusTemporaryRedirect, r.WrittenHeaderInt)
}
示例5: TestSetHttpResponseWriter
func TestSetHttpResponseWriter(t *testing.T) {
responseWriter := new(http_test.TestResponseWriter)
testRequest, _ := http.NewRequest("GET", "http://goweb.org/people/123", nil)
codecService := codecsservices.NewWebCodecService()
c := NewWebContext(responseWriter, testRequest, codecService)
responseWriter2 := new(http_test.TestResponseWriter)
responseWriter2.Header().Set("Something", "true")
testRequest2, _ := http.NewRequest("PUT", "http://goweb.org/people/123", nil)
c.SetHttpRequest(testRequest2)
c.SetHttpResponseWriter(responseWriter2)
req := c.HttpRequest()
res := c.HttpResponseWriter()
assert.Equal(t, &testRequest2, &req)
assert.Equal(t, responseWriter2, res)
}