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

Function Test_PaginateWithOffset

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

Source from the content-addressed store, hash-verified

372}
373
374func Test_PaginateWithOffset(t *testing.T) {
375 t.Parallel()
376 app := fiber.New()
377 app.Use(New())
378
379 app.Get("/", func(c fiber.Ctx) error {
380 pageInfo, ok := FromContext(c)
381 if !ok {
382 return fiber.ErrBadRequest
383 }
384 return c.JSON(paginateResponse{
385 Page: pageInfo.Page,
386 Limit: pageInfo.Limit,
387 Offset: pageInfo.Offset,
388 Start: pageInfo.Start(),
389 Sort: pageInfo.Sort,
390 })
391 })
392
393 resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/?offset=20&limit=20", http.NoBody))
394 require.NoError(t, err)
395 defer resp.Body.Close() //nolint:errcheck // close error not relevant in tests
396 require.Equal(t, fiber.StatusOK, resp.StatusCode)
397
398 var body paginateResponse
399 require.NoError(t, json.NewDecoder(resp.Body).Decode(&body))
400
401 require.Equal(t, 1, body.Page)
402 require.Equal(t, 20, body.Limit)
403 require.Equal(t, 20, body.Offset)
404 require.Equal(t, 20, body.Start)
405}
406
407func Test_PaginateCheckDefaultsWhenNoQueries(t *testing.T) {
408 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