| 68 | } |
| 69 | |
| 70 | func TestControllerMethodResult(t *testing.T) { |
| 71 | app := iris.New() |
| 72 | New(app).Handle(new(testControllerMethodResult)) |
| 73 | |
| 74 | e := httptest.New(t, app) |
| 75 | |
| 76 | e.GET("/").Expect().Status(iris.StatusOK). |
| 77 | Body().IsEqual("Hello World!") |
| 78 | |
| 79 | e.GET("/with/status").Expect().Status(iris.StatusNotFound). |
| 80 | Body().IsEqual("This page doesn't exist") |
| 81 | |
| 82 | e.GET("/json").Expect().Status(iris.StatusOK). |
| 83 | JSON().IsEqual(iris.Map{ |
| 84 | "name": "Iris", |
| 85 | "age": 2, |
| 86 | }) |
| 87 | |
| 88 | e.GET("/json").WithQuery("err", true).Expect(). |
| 89 | Status(iris.StatusBadRequest). |
| 90 | Body().IsEqual("error here") |
| 91 | |
| 92 | e.GET("/thing/with/try/1").Expect(). |
| 93 | Status(iris.StatusOK). |
| 94 | Body().IsEqual("thing 1") |
| 95 | // failure because of index exceed the slice |
| 96 | e.GET("/thing/with/try/3").Expect(). |
| 97 | Status(iris.StatusNotFound). |
| 98 | Body().IsEqual("thing does not exist") |
| 99 | |
| 100 | e.GET("/thing/with/try/default/3").Expect(). |
| 101 | Status(iris.StatusBadRequest). |
| 102 | Body().IsEqual("Bad Request") |
| 103 | } |
| 104 | |
| 105 | type testControllerMethodResultTypes struct { |
| 106 | Ctx *context.Context |