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

Function TestControllerBeginAndEndRequestFuncBindMiddleware

mvc/controller_test.go:146–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestControllerBeginAndEndRequestFuncBindMiddleware(t *testing.T) {
147 app := iris.New()
148 usernames := map[string]bool{
149 "kataras": true,
150 "makis": false,
151 "efi": true,
152 "rg": false,
153 "bill": true,
154 "whoisyourdaddy": false,
155 }
156 middlewareCheck := func(ctx *context.Context) {
157 for username, allow := range usernames {
158 if ctx.Params().Get("username") == username && allow {
159 ctx.Next()
160 return
161 }
162 }
163
164 ctx.StatusCode(iris.StatusForbidden)
165 ctx.Writef("forbidden")
166 }
167
168 app.PartyFunc("/profile/{username}", func(r iris.Party) {
169 r.Use(middlewareCheck)
170 New(r).Handle(new(testControllerBeginAndEndRequestFunc))
171 })
172
173 e := httptest.New(t, app)
174
175 doneResponse := "done"
176
177 for username, allow := range usernames {
178 getEx := e.GET("/profile/" + username).Expect()
179 if allow {
180 getEx.Status(iris.StatusOK).
181 Body().IsEqual(username + doneResponse)
182 } else {
183 getEx.Status(iris.StatusForbidden).Body().IsEqual("forbidden")
184 }
185
186 postEx := e.POST("/profile/" + username).Expect()
187 if allow {
188 postEx.Status(iris.StatusOK).
189 Body().IsEqual(username + doneResponse)
190 } else {
191 postEx.Status(iris.StatusForbidden).Body().IsEqual("forbidden")
192 }
193 }
194}
195
196type Model struct {
197 Username string

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
NewMethod · 0.80
ParamsMethod · 0.80
NextMethod · 0.80
WritefMethod · 0.80
StatusMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
StatusCodeMethod · 0.65
PartyFuncMethod · 0.65
UseMethod · 0.65
HandleMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…