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

Function TestControllerOverlap

mvc/controller_overlap_test.go:14–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func 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
50type AuthenticatedTest uint64
51

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
NewFunction · 0.92
NewMethod · 0.80
StatusMethod · 0.80
PartyMethod · 0.65
SetRegisterRuleMethod · 0.65
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…