(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestControllerOverlap(t *testing.T) { |
| 15 | app := iris.New() |
| 16 | userRouter := app.Party("/user") |
| 17 | { |
| 18 | userRouter.SetRegisterRule(iris.RouteOverlap) |
| 19 | |
| 20 | // Initialize a new MVC application on top of the "userRouter". |
| 21 | userApp := mvc.New(userRouter) |
| 22 | // Register Dependencies. |
| 23 | userApp.Register(authDependency) |
| 24 | |
| 25 | // Register Controllers. |
| 26 | userApp.Handle(new(AuthenticatedUserController)) |
| 27 | userApp.Handle(new(UnauthenticatedUserController)) |
| 28 | } |
| 29 | |
| 30 | e := httptest.New(t, app) |
| 31 | e.GET("/user").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual("unauth") |
| 32 | // Test raw stop execution with a status code sent on the controller's method. |
| 33 | e.GET("/user/with/status/on/method").Expect().Status(httptest.StatusBadRequest).Body().IsEqual("unauth") |
| 34 | // Test stop execution with status but last code sent through the controller's method. |
| 35 | e.GET("/user/with/status/on/method/too").Expect().Status(httptest.StatusInternalServerError).Body().IsEqual("unauth") |
| 36 | // Test raw stop execution and no status code sent on controller's method (should be OK). |
| 37 | e.GET("/user/with/no/status").Expect().Status(httptest.StatusOK).Body().IsEqual("unauth") |
| 38 | |
| 39 | // Test authenticated request. |
| 40 | e.GET("/user").WithQuery("id", 42).Expect().Status(httptest.StatusOK).Body().IsEqual("auth: 42") |
| 41 | |
| 42 | // Test HandleHTTPError method accepts a not found and returns a 404 |
| 43 | // from a shared controller and overlapped, the url parameter matters because this method was overlapped. |
| 44 | e.GET("/user/notfound").Expect().Status(httptest.StatusBadRequest). |
| 45 | Body().IsEqual("error: *mvc_test.UnauthenticatedUserController: from: 404 to: 400") |
| 46 | e.GET("/user/notfound").WithQuery("id", 42).Expect().Status(httptest.StatusBadRequest). |
| 47 | Body().IsEqual("error: *mvc_test.AuthenticatedUserController: from: 404 to: 400") |
| 48 | } |
| 49 | |
| 50 | type AuthenticatedTest uint64 |
| 51 |
nothing calls this directly
no test coverage detected
searching dependent graphs…