MCPcopy Create free account
hub / github.com/kataras/iris / TestControllerHandle

Function TestControllerHandle

mvc/controller_handle_test.go:117–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

115}
116
117func TestControllerHandle(t *testing.T) {
118 app := iris.New()
119 m := New(app)
120 m.Register(&testServiceImpl{prefix: "service:"})
121 m.Handle(new(testControllerHandle))
122 m.Handle(new(testSmallController))
123
124 e := httptest.New(t, app)
125
126 // test the index, is not part of the current package's implementation but do it.
127 e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual("index")
128
129 // the important things now.
130
131 // this test ensures that the BeginRequest of the controller will be
132 // called correctly and also the controller is binded to the first input argument
133 // (which is the function's receiver, if any, in this case the *testController in go).
134 expectedReqField := "this is a request field filled by this url param"
135 e.GET("/histatic").WithQuery("reqfield", expectedReqField).Expect().Status(httptest.StatusOK).
136 Body().IsEqual(expectedReqField)
137 // this test makes sure that the binded values of the controller is handled correctly
138 // and can be used in a user-defined, dynamic "mvc handler".
139 e.GET("/hiservice").Expect().Status(httptest.StatusOK).
140 Body().IsEqual("service: hi")
141 e.GET("/hiservice/value").Expect().Status(httptest.StatusOK).
142 Body().IsEqual("service: hi with param: value")
143 // this worked with a temporary variadic on the resolvemethodfunc which is not
144 // correct design, I should split the path and params with the rest of implementation
145 // in order a simple template.Src can be given.
146 e.GET("/hiparam/value").Expect().Status(httptest.StatusOK).
147 Body().IsEqual("value")
148 e.GET("/hiparamempyinput/value").Expect().Status(httptest.StatusOK).
149 Body().IsEqual("empty in but served with ctx.Params.Get('ps')=value")
150 e.GET("/custom/value1").Expect().Status(httptest.StatusOK).
151 Body().IsEqual("value1")
152 e.GET("/custom2/value2").Expect().Status(httptest.StatusOK).
153 Body().IsEqual("value2")
154 e.GET("/custom3/value1/value2").Expect().Status(httptest.StatusOK).
155 Body().IsEqual("value1value2")
156 e.GET("/custom3/value1").Expect().Status(httptest.StatusNotFound)
157
158 e.GET("/hi/param/empty/input/with/ctx/value").Expect().Status(httptest.StatusOK).
159 Body().IsEqual("empty in but served with ctx.Params.Get('param2')= value == id == value")
160}
161
162type testControllerHandleWithDynamicPathPrefix struct {
163 Ctx iris.Context

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
NewMethod · 0.80
StatusMethod · 0.80
NewFunction · 0.70
RegisterMethod · 0.65
HandleMethod · 0.65
BodyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…