MCPcopy
hub / github.com/Tencent/WeKnora / TestAPI_PaginateIgnoredForPOST

Function TestAPI_PaginateIgnoredForPOST

cli/cmd/api/api_test.go:373–395  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

371}
372
373func TestAPI_PaginateIgnoredForPOST(t *testing.T) {
374 // --paginate should be a no-op for non-GET methods (no pagination
375 // semantic for POST/PUT/DELETE). Single call expected.
376 called := 0
377 svc := &fakeAPISvc{do: func(method, path string, _ any) (*http.Response, error) {
378 called++
379 return &http.Response{
380 StatusCode: 200,
381 Body: io.NopCloser(bytes.NewReader([]byte(`{"success":true,"data":[],"total":5,"page":1,"page_size":2}`))),
382 Header: make(http.Header),
383 }, nil
384 }}
385
386 _, _ = iostreams.SetForTest(t)
387
388 opts := &Options{Input: "-", StdinReader: strings.NewReader(`{"name":"foo"}`)}
389 if err := runAPI(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatJSON}, svc, "POST", "/api/v1/knowledge-base", true); err != nil {
390 t.Fatalf("runAPI: %v", err)
391 }
392 if called != 1 {
393 t.Errorf("called %d times, want 1 (POST should not paginate)", called)
394 }
395}
396
397func TestAPI_PaginateNoMetadataPassesThrough(t *testing.T) {
398 // If response doesn't look paginated (no total/page/page_size), --paginate

Callers

nothing calls this directly

Calls 2

SetForTestFunction · 0.92
runAPIFunction · 0.85

Tested by

no test coverage detected