| 219 | } |
| 220 | |
| 221 | func TestContextJSON(t *testing.T) { |
| 222 | e := New() |
| 223 | rec := httptest.NewRecorder() |
| 224 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userJSON)) |
| 225 | c := e.NewContext(req, rec) |
| 226 | |
| 227 | err := c.JSON(http.StatusOK, user{ID: 1, Name: "Jon Snow"}) |
| 228 | if assert.NoError(t, err) { |
| 229 | assert.Equal(t, http.StatusOK, rec.Code) |
| 230 | assert.Equal(t, MIMEApplicationJSON, rec.Header().Get(HeaderContentType)) |
| 231 | assert.Equal(t, userJSON+"\n", rec.Body.String()) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | func TestContextJSONErrorsOut(t *testing.T) { |
| 236 | e := New() |