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

Function Test_PaginateConfigPageKeyLimitKey

middleware/paginate/paginate_test.go:534–566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

532}
533
534func Test_PaginateConfigPageKeyLimitKey(t *testing.T) {
535 t.Parallel()
536 app := fiber.New()
537 app.Use(New(Config{
538 PageKey: "site",
539 LimitKey: "size",
540 DefaultSort: "id",
541 }))
542
543 app.Get("/", func(c fiber.Ctx) error {
544 pageInfo, ok := FromContext(c)
545 if !ok {
546 return fiber.ErrBadRequest
547 }
548 return c.JSON(paginateResponse{
549 Page: pageInfo.Page,
550 Limit: pageInfo.Limit,
551 Start: pageInfo.Start(),
552 Sort: pageInfo.Sort,
553 })
554 })
555
556 resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/?site=2&size=5", http.NoBody))
557 require.NoError(t, err)
558 defer resp.Body.Close() //nolint:errcheck // close error not relevant in tests
559
560 var body paginateResponse
561 require.NoError(t, json.NewDecoder(resp.Body).Decode(&body))
562
563 require.Equal(t, 2, body.Page)
564 require.Equal(t, 5, body.Limit)
565 require.Equal(t, 5, body.Start)
566}
567
568func Test_PaginateNegativeDefaultPageDefaultLimitValues(t *testing.T) {
569 t.Parallel()

Callers

nothing calls this directly

Calls 9

TestMethod · 0.80
NewFunction · 0.70
FromContextFunction · 0.70
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
JSONMethod · 0.65
StartMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected