1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-22 04:17:03 +00:00

Helpers for third-party adaptors and middleware authors to generate route paths without even know the router that has being selected by user

Former-commit-id: b21147f2bc306d5c41539a1be0c83456c3d62651
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-02-28 15:01:18 +02:00
parent b214df742b
commit 064282036c
8 changed files with 163 additions and 71 deletions

View File

@@ -246,3 +246,19 @@ func TestHTTPRouterRegexMiddleware(t *testing.T) {
e.GET("/profile/gerasimosmaropoulos").Expect().Status(iris.StatusOK)
e.GET("/profile/anumberof42").Expect().Status(iris.StatusNotFound)
}
func TestHTTPRouterRouteParamAndWildcardPath(t *testing.T) {
app := newHTTPRouterApp()
routePath := app.RouteWildcardPath("/profile/"+app.RouteParam("user_id")+"/"+app.RouteParam("ref")+"/", "anything")
expectedRoutePath := "/profile/:user_id/:ref/*anything"
if routePath != expectedRoutePath {
t.Fatalf("HTTPRouter Error on RouteParam and RouteWildcardPath, expecting '%s' but got '%s'", expectedRoutePath, routePath)
}
app.Get(routePath, func(ctx *iris.Context) {
ctx.Writef(ctx.Path())
})
e := httptest.New(app, t)
e.GET("/profile/42/areference/anythinghere").Expect().Status(iris.StatusOK).Body().Equal("/profile/42/areference/anythinghere")
}