(t *testing.T)
| 144 | } |
| 145 | |
| 146 | func 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 | |
| 196 | type Model struct { |
| 197 | Username string |
nothing calls this directly
no test coverage detected
searching dependent graphs…