当前位置: 首页>>代码示例>>Golang>>正文


Golang TestResponseWriter.Header方法代码示例

本文整理汇总了Golang中github.com/stretchr/testify/http.TestResponseWriter.Header方法的典型用法代码示例。如果您正苦于以下问题:Golang TestResponseWriter.Header方法的具体用法?Golang TestResponseWriter.Header怎么用?Golang TestResponseWriter.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/stretchr/testify/http.TestResponseWriter的用法示例。


在下文中一共展示了TestResponseWriter.Header方法的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
}
开发者ID:pcl,项目名称:httptest,代码行数:25,代码来源:route_runner.go

示例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)

}
开发者ID:antianlu,项目名称:goweb,代码行数:8,代码来源:helpers_test.go

示例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)

}
开发者ID:rmulley,项目名称:goweb,代码行数:8,代码来源:helpers_test.go

示例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)

}
开发者ID:rmulley,项目名称:goweb,代码行数:8,代码来源:helpers_test.go

示例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)

}
开发者ID:nelsam,项目名称:goweb,代码行数:22,代码来源:web_context_test.go


注:本文中的github.com/stretchr/testify/http.TestResponseWriter.Header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。