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

Function Test_PaginateWithCursor

middleware/paginate/paginate_test.go:823–854  ·  view source on GitHub ↗

--- Cursor tests ---

(t *testing.T)

Source from the content-addressed store, hash-verified

821// --- Cursor tests ---
822
823func Test_PaginateWithCursor(t *testing.T) {
824 t.Parallel()
825 app := fiber.New()
826 app.Use(New(Config{
827 DefaultSort: "id",
828 }))
829
830 app.Get("/", func(c fiber.Ctx) error {
831 pageInfo, ok := FromContext(c)
832 if !ok {
833 return fiber.ErrBadRequest
834 }
835 return c.JSON(cursorResponse{
836 Cursor: pageInfo.Cursor,
837 Limit: pageInfo.Limit,
838 Sort: pageInfo.Sort,
839 })
840 })
841
842 cursorJSON := `{"id":42}`
843 cursor := base64.RawURLEncoding.EncodeToString([]byte(cursorJSON))
844
845 resp, err := app.Test(httptest.NewRequest(http.MethodGet, "/?cursor="+cursor+"&limit=20", http.NoBody))
846 require.NoError(t, err)
847 defer resp.Body.Close() //nolint:errcheck // close error not relevant in tests
848 require.Equal(t, 200, resp.StatusCode)
849
850 var result cursorResponse
851 require.NoError(t, json.NewDecoder(resp.Body).Decode(&result))
852 require.Equal(t, cursor, result.Cursor)
853 require.Equal(t, 20, result.Limit)
854}
855
856func Test_PaginateCursorPriorityOverPage(t *testing.T) {
857 t.Parallel()

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected