本文整理匯總了Golang中github.com/MG-RAST/golib/stretchr/goweb/handlers/test.TestHandler.Handle方法的典型用法代碼示例。如果您正苦於以下問題:Golang TestHandler.Handle方法的具體用法?Golang TestHandler.Handle怎麽用?Golang TestHandler.Handle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/golib/stretchr/goweb/handlers/test.TestHandler
的用法示例。
在下文中一共展示了TestHandler.Handle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestBeforeAndAfterHandlers
func TestBeforeAndAfterHandlers(t *testing.T) {
responseWriter := new(http_test.TestResponseWriter)
testRequest, _ := http.NewRequest("GET", "http://stretchr.org/goweb", nil)
codecService := codecsservices.NewWebCodecService()
handler := NewHttpHandler(codecService)
// setup some test handlers
handler1 := new(handlers_test.TestHandler)
handler2 := new(handlers_test.TestHandler)
handler3 := new(handlers_test.TestHandler)
handler.MapBefore(func(c context.Context) error {
_, err := handler1.Handle(c)
return err
})
handler.Map(func(c context.Context) error {
_, err := handler2.Handle(c)
return err
})
handler.MapAfter(func(c context.Context) error {
_, err := handler3.Handle(c)
return err
})
handler1.On("Handle", mock.Anything).Return(false, nil)
handler2.On("Handle", mock.Anything).Return(false, nil)
handler3.On("Handle", mock.Anything).Return(false, nil)
handler.ServeHTTP(responseWriter, testRequest)
mock.AssertExpectationsForObjects(t, handler1.Mock, handler2.Mock, handler3.Mock)
// make sure it's always the same context
ctx1 := handler1.Calls[0].Arguments[0].(context.Context)
ctx2 := handler2.Calls[0].Arguments[0].(context.Context)
ctx3 := handler3.Calls[0].Arguments[0].(context.Context)
assert.Equal(t, ctx1, ctx2, "Contexts should be the same")
assert.Equal(t, ctx2, ctx3, "Contexts should be the same")
}