MCPcopy Index your code
hub / github.com/apache/answer / TestPagination

Function TestPagination

plugin/plugin_test/kv_storage_test.go:250–298  ·  view source on GitHub ↗

Test pagination in GetByGroup

(t *testing.T)

Source from the content-addressed store, hash-verified

248
249// Test pagination in GetByGroup
250func TestPagination(t *testing.T) {
251 setupTestEnvironment()
252 kv := testPlugin.operator
253 ctx := context.Background()
254 totalItems := 25
255
256 for i := range totalItems {
257 mustSet(t, kv, ctx, "pagination", fmt.Sprintf("key%d", i), fmt.Sprintf("value%d", i))
258 }
259
260 // Test pagination
261 page1, err := kv.GetByGroup(ctx, plugin.KVParams{Group: "pagination", Page: 1, PageSize: 10})
262 if err != nil {
263 t.Fatalf("Failed to get page 1: %v", err)
264 }
265 if len(page1) != 10 {
266 t.Errorf("Page 1: expected 10 items, got %d", len(page1))
267 }
268
269 page2, err := kv.GetByGroup(ctx, plugin.KVParams{Group: "pagination", Page: 2, PageSize: 10})
270 if err != nil {
271 t.Fatalf("Failed to get page 2: %v", err)
272 }
273 if len(page2) != 10 {
274 t.Errorf("Page 2: expected 10 items, got %d", len(page2))
275 }
276
277 page3, err := kv.GetByGroup(ctx, plugin.KVParams{Group: "pagination", Page: 3, PageSize: 10})
278 if err != nil {
279 t.Fatalf("Failed to get page 3: %v", err)
280 }
281 if len(page3) != 5 {
282 t.Errorf("Page 3: expected 5 items, got %d", len(page3))
283 }
284
285 // Verify different keys on different pages
286 for i := range 10 {
287 key := fmt.Sprintf("key%d", i)
288 if _, ok := page1[key]; !ok {
289 t.Errorf("Pagination test failed, key %s should be on page 1", key)
290 }
291 }
292 for i := range 10 {
293 key := fmt.Sprintf("key%d", i+10)
294 if _, ok := page2[key]; !ok {
295 t.Errorf("Pagination test failed, key %s should be on page 2", key)
296 }
297 }
298}
299
300// Test concurrent operations and performance
301func TestConcurrency(t *testing.T) {

Callers

nothing calls this directly

Calls 3

setupTestEnvironmentFunction · 0.85
mustSetFunction · 0.85
GetByGroupMethod · 0.80

Tested by

no test coverage detected