add a test for controller.GetBy-only method... it passes as expected https://github.com/kataras/iris/issues/1487

Former-commit-id: 5f4abd4a8c6528d666d91315fa515a4a607326fc
This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-04-17 16:03:11 +03:00
parent 1bb76853a9
commit c0e6f9e4d9

View File

@ -175,3 +175,24 @@ func TestControllerHandleWithDynamicPathPrefix(t *testing.T) {
e.GET("/api/data/mymodel/myaction/myid").Expect().Status(httptest.StatusOK). e.GET("/api/data/mymodel/myaction/myid").Expect().Status(httptest.StatusOK).
Body().Equal("mymodelmyactionmyid") Body().Equal("mymodelmyactionmyid")
} }
type testControllerGetBy struct{}
func (c *testControllerGetBy) GetBy(age int64) *testCustomStruct {
return &testCustomStruct{
Age: int(age),
Name: "name",
}
}
func TestControllerGetBy(t *testing.T) {
// Tests only GetBy.
app := iris.New()
app.Configure(iris.WithFireMethodNotAllowed)
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)
}