From c0e6f9e4d98ae4748fec5e32d4457497ed3227fd Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 17 Apr 2020 16:03:11 +0300 Subject: [PATCH] add a test for controller.GetBy-only method... it passes as expected https://github.com/kataras/iris/issues/1487 Former-commit-id: 5f4abd4a8c6528d666d91315fa515a4a607326fc --- mvc/controller_handle_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mvc/controller_handle_test.go b/mvc/controller_handle_test.go index f2fdceba..eadc0945 100644 --- a/mvc/controller_handle_test.go +++ b/mvc/controller_handle_test.go @@ -175,3 +175,24 @@ func TestControllerHandleWithDynamicPathPrefix(t *testing.T) { e.GET("/api/data/mymodel/myaction/myid").Expect().Status(httptest.StatusOK). 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) +}