| 430 | } |
| 431 | |
| 432 | func Test_App_Errors(t *testing.T) { |
| 433 | t.Parallel() |
| 434 | app := New(Config{ |
| 435 | BodyLimit: 4, |
| 436 | }) |
| 437 | |
| 438 | app.Get("/", func(_ Ctx) error { |
| 439 | return errors.New("hi, i'm an error") |
| 440 | }) |
| 441 | |
| 442 | resp, err := app.Test(httptest.NewRequest(MethodGet, "/", http.NoBody)) |
| 443 | require.NoError(t, err, "app.Test(req)") |
| 444 | require.Equal(t, 500, resp.StatusCode, "Status code") |
| 445 | |
| 446 | body, err := io.ReadAll(resp.Body) |
| 447 | require.NoError(t, err) |
| 448 | require.Equal(t, "hi, i'm an error", string(body)) |
| 449 | |
| 450 | _, err = app.Test(httptest.NewRequest(MethodGet, "/", strings.NewReader("big body"))) |
| 451 | if err != nil { |
| 452 | require.Equal(t, "body size exceeds the given limit", err.Error(), "app.Test(req)") |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | func Test_App_BodyLimit_Negative(t *testing.T) { |
| 457 | t.Parallel() |