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

Implement the Status Method Not Allowed for gorilla mux too and add some tests

Former-commit-id: b157bacfa15567b8c98f959f3359e025fdf1b205
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-02-21 14:20:31 +02:00
parent 6fca78d12a
commit b25d99870e
5 changed files with 164 additions and 10 deletions

View File

@@ -268,3 +268,27 @@ func TestHTTPRouterRouteURLPath(t *testing.T) {
t.Fatalf("httprouter's reverse routing 'URLPath' error: expected %s but got %s", expected, got)
}
}
func TestHTTPRouterFireMethodNotAllowed(t *testing.T) {
app := iris.New()
app.Adapt(httprouter.New())
app.Config.FireMethodNotAllowed = true
h := func(ctx *iris.Context) {
ctx.WriteString(ctx.Method())
}
app.OnError(iris.StatusMethodNotAllowed, func(ctx *iris.Context) {
ctx.WriteString("Hello from my custom 405 page")
})
app.Get("/mypath", h)
app.Put("/mypath", h)
e := httptest.New(app, t)
e.GET("/mypath").Expect().Status(iris.StatusOK).Body().Equal("GET")
e.PUT("/mypath").Expect().Status(iris.StatusOK).Body().Equal("PUT")
// this should fail with 405 and catch by the custom http error
e.POST("/mypath").Expect().Status(iris.StatusMethodNotAllowed).Body().Equal("Hello from my custom 405 page")
}