1
0
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:
Gerasimos (Makis) Maropoulos
2020-04-19 12:05:22 +03:00
parent dcf02480b3
commit 340664dca9
4 changed files with 50 additions and 8 deletions

View File

@@ -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)
}