MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestClientPaginateBasic

Function TestClientPaginateBasic

mcp/client_test.go:77–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestClientPaginateBasic(t *testing.T) {
78 ctx := context.Background()
79 testCases := []struct {
80 name string
81 results []*ListTestResult
82 mockError error
83 initialParams *ListTestParams
84 expected []*Item
85 expectError bool
86 }{
87 {
88 name: "SinglePageAllItems",
89 results: generatePaginatedResults(allItems, len(allItems)),
90 expected: allItems,
91 },
92 {
93 name: "MultiplePages",
94 results: generatePaginatedResults(allItems, 3),
95 expected: allItems,
96 },
97 {
98 name: "EmptyResults",
99 results: generatePaginatedResults([]*Item{}, 10),
100 expected: nil,
101 },
102 {
103 name: "ListFuncReturnsErrorImmediately",
104 results: []*ListTestResult{{}},
105 mockError: fmt.Errorf("API error on first call"),
106 expected: nil,
107 expectError: true,
108 },
109 {
110 name: "InitialCursorProvided",
111 initialParams: &ListTestParams{Cursor: "cursor_2"},
112 results: generatePaginatedResults(allItems[2:], 3),
113 expected: allItems[2:],
114 },
115 {
116 name: "CursorBeyondAllItems",
117 initialParams: &ListTestParams{Cursor: "cursor_999"},
118 results: []*ListTestResult{{Items: []*Item{}, NextCursor: ""}},
119 expected: nil,
120 },
121 }
122
123 for _, tc := range testCases {
124 t.Run(tc.name, func(t *testing.T) {
125 listFunc := func(ctx context.Context, params *ListTestParams) (*ListTestResult, error) {
126 if len(tc.results) == 0 {
127 t.Fatalf("listFunc called but no more results defined for test case %q", tc.name)
128 }
129 res := tc.results[0]
130 tc.results = tc.results[1:]
131 var err error
132 if tc.mockError != nil {
133 err = tc.mockError
134 }

Callers

nothing calls this directly

Calls 3

generatePaginatedResultsFunction · 0.85
paginateFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…