mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 04:51:56 +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:
@@ -255,3 +255,27 @@ func TestGorillaMuxRouteURLPath(t *testing.T) {
|
||||
t.Fatalf("gorillamux' reverse routing 'URLPath' error: expected %s but got %s", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGorillaMuxFireMethodNotAllowed(t *testing.T) {
|
||||
app := iris.New()
|
||||
app.Adapt(gorillamux.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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user