mirror of
https://github.com/kataras/iris.git
synced 2025-12-23 21:07:03 +00:00
add test for hero/Container.UseResultHandler
Former-commit-id: 8954541f8da055f30965cce07a85f485580fee48
This commit is contained in:
@@ -97,3 +97,35 @@ func TestContainerInject(t *testing.T) {
|
||||
t.Fatalf("[service] expected: %#+v but got: %#+v", expected3, got3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainerUseResultHandler(t *testing.T) {
|
||||
c := New()
|
||||
resultLogger := func(next ResultHandler) ResultHandler {
|
||||
return func(ctx iris.Context, v interface{}) error {
|
||||
t.Logf("%#+v", v)
|
||||
return next(ctx, v)
|
||||
}
|
||||
}
|
||||
|
||||
c.UseResultHandler(resultLogger)
|
||||
expectedResponse := map[string]interface{}{"injected": true}
|
||||
c.UseResultHandler(func(next ResultHandler) ResultHandler {
|
||||
return func(ctx iris.Context, v interface{}) error {
|
||||
return next(ctx, expectedResponse)
|
||||
}
|
||||
})
|
||||
c.UseResultHandler(resultLogger)
|
||||
|
||||
handler := c.Handler(func(id int) testOutput {
|
||||
return testOutput{
|
||||
ID: id,
|
||||
Name: "kataras",
|
||||
}
|
||||
})
|
||||
|
||||
app := iris.New()
|
||||
app.Get("/{id:int}", handler)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/42").Expect().Status(httptest.StatusOK).JSON().Equal(expectedResponse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user