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

Function TestServerPaginateVariousPageSizes

mcp/server_test.go:204–237  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

202}
203
204func TestServerPaginateVariousPageSizes(t *testing.T) {
205 fs := newFeatureSet(func(t *testItem) string { return t.Name })
206 fs.add(allTestItems...)
207 // Try all possible page sizes, ensuring we get the correct list of items.
208 for pageSize := 1; pageSize < len(allTestItems)+1; pageSize++ {
209 var gotItems []*testItem
210 var nextCursor string
211 wantChunks := slices.Collect(slices.Chunk(allTestItems, pageSize))
212 index := 0
213 // Iterate through all pages, comparing sub-slices to the paginated list.
214 for {
215 params := &testListParams{Cursor: nextCursor}
216 gotResult, err := paginateList(fs, pageSize, params, &testListResult{}, func(res *testListResult, items []*testItem) {
217 res.Items = items
218 })
219 if err != nil {
220 t.Fatalf("paginateList() unexpected error for pageSize %d, cursor %q: %v", pageSize, nextCursor, err)
221 }
222 if diff := cmp.Diff(wantChunks[index], gotResult.Items); diff != "" {
223 t.Errorf("paginateList mismatch (-want +got):\n%s", diff)
224 }
225 gotItems = append(gotItems, gotResult.Items...)
226 nextCursor = gotResult.NextCursor
227 if nextCursor == "" {
228 break
229 }
230 index++
231 }
232
233 if len(gotItems) != len(allTestItems) {
234 t.Fatalf("paginateList() returned %d items, want %d", len(allTestItems), len(gotItems))
235 }
236 }
237}
238
239func TestServerCapabilities(t *testing.T) {
240 tool := &Tool{Name: "t", InputSchema: &jsonschema.Schema{Type: "object"}}

Callers

nothing calls this directly

Calls 3

newFeatureSetFunction · 0.85
paginateListFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…