1package v2
2
3import (
4	"context"
5	"testing"
6)
7
8func TestPageSizeFromContext(t *testing.T) {
9	tests := []struct {
10		description string
11		ctx         context.Context
12		expected    int
13	}{
14		{
15			description: "it returns 0 if there is no page size in the context",
16			ctx:         context.Background(),
17			expected:    0,
18		},
19		{
20			description: "it returns the page size set in the context",
21			ctx:         context.WithValue(context.Background(), PageSizeKey, 500),
22			expected:    500,
23		},
24	}
25
26	for _, test := range tests {
27		t.Run(test.description, func(t *testing.T) {
28			got := PageSizeFromContext(test.ctx)
29
30			if got != test.expected {
31				t.Errorf("got %v, expected %v", got, test.expected)
32			}
33		})
34	}
35}
36
37func TestPageContinueFromContext(t *testing.T) {
38	tests := []struct {
39		description string
40		ctx         context.Context
41		expected    string
42	}{
43		{
44			description: "it returns an empty string if there is no continue token in the context",
45			ctx:         context.Background(),
46			expected:    "",
47		},
48		{
49			description: "it returns the continue token set in the context",
50			ctx:         context.WithValue(context.Background(), PageContinueKey, "sartre"),
51			expected:    "sartre",
52		},
53	}
54
55	for _, test := range tests {
56		t.Run(test.description, func(t *testing.T) {
57			got := PageContinueFromContext(test.ctx)
58
59			if got != test.expected {
60				t.Errorf("got %v, expected %v", got, test.expected)
61			}
62		})
63	}
64}
65