MCPcopy
hub / github.com/gofiber/fiber / Test_App_Errors

Function Test_App_Errors

app_test.go:432–454  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

430}
431
432func 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
456func Test_App_BodyLimit_Negative(t *testing.T) {
457 t.Parallel()

Callers

nothing calls this directly

Calls 5

TestMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
NewMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected