1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 09:57:01 +00:00
Former-commit-id: 85c8b1e20da6e39485478025ef1b0f80ef953e4a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-04-21 09:27:28 +03:00
parent 6c6de6b85d
commit 0cf5d5a4a3
4 changed files with 46 additions and 25 deletions

View File

@@ -185,14 +185,17 @@ func (c *testControllerGetBy) GetBy(age int64) *testCustomStruct {
}
}
func TestControllerGetBy(t *testing.T) {
// Tests only GetBy.
func TestControllerGetByWithAllowMethods(t *testing.T) {
app := iris.New()
app.Configure(iris.WithFireMethodNotAllowed)
// ^ this 405 status will not be fired on POST: project/... because of
// .AllowMethods, but it will on PUT.
New(app.Party("/project").AllowMethods(iris.MethodGet, iris.MethodPost)).Handle(new(testControllerGetBy))
New(app.Party("/project")).Handle(new(testControllerGetBy))
e := httptest.New(t, app)
e.GET("/project/42").Expect().Status(httptest.StatusOK).
JSON().Equal(&testCustomStruct{Age: 42, Name: "name"})
e.POST("/project/42").Expect().Status(httptest.StatusMethodNotAllowed)
e.POST("/project/42").Expect().Status(httptest.StatusOK)
e.PUT("/project/42").Expect().Status(httptest.StatusMethodNotAllowed)
}