mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
add test for binding a whole function as an input argument on the handler's function - worked
Former-commit-id: 410ffdf44057ce57d5d280aa80ef0c9884f275b2
This commit is contained in:
parent
43c330f338
commit
d72c649441
|
@ -101,3 +101,29 @@ func testAppWithMvcHandlers(t *testing.T, h1, h2, h3 iris.Handler) {
|
|||
e.GET("/param/the_param_value").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("param is: the_param_value")
|
||||
}
|
||||
|
||||
// TestBindFunctionAsFunctionInputArgument tests to bind
|
||||
// a whole dynamic function based on the current context
|
||||
// as an input argument in the mvc-like handler's function.
|
||||
func TestBindFunctionAsFunctionInputArgument(t *testing.T) {
|
||||
app := iris.New()
|
||||
postsBinder := func(ctx iris.Context) func(string) string {
|
||||
return ctx.PostValue // or FormValue, the same here.
|
||||
}
|
||||
|
||||
h := MustMakeHandler(func(get func(string) string) string {
|
||||
// send the `ctx.PostValue/FormValue("username")` value
|
||||
// to the client.
|
||||
return get("username")
|
||||
},
|
||||
// bind the function binder.
|
||||
reflect.ValueOf(postsBinder))
|
||||
|
||||
app.Post("/", h)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
|
||||
expectedUsername := "kataras"
|
||||
e.POST("/").WithFormField("username", expectedUsername).
|
||||
Expect().Status(iris.StatusOK).Body().Equal(expectedUsername)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user