MCPcopy
hub / github.com/larksuite/cli / TestStreamPages_BatchAPI_WithArrayField

Function TestStreamPages_BatchAPI_WithArrayField

internal/client/client_test.go:154–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func TestStreamPages_BatchAPI_WithArrayField(t *testing.T) {
155 rt := roundTripFunc(func(req *http.Request) (*http.Response, error) {
156 return jsonResponse(map[string]interface{}{
157 "code": 0, "msg": "ok",
158 "data": map[string]interface{}{
159 "items": []interface{}{map[string]interface{}{"id": "1"}, map[string]interface{}{"id": "2"}},
160 "has_more": false,
161 },
162 }), nil
163 })
164
165 ac, errBuf := newTestAPIClient(t, rt)
166
167 var streamedItems []interface{}
168 result, hasItems, err := ac.StreamPages(context.Background(), RawApiRequest{
169 Method: "GET",
170 URL: "/open-apis/contact/v3/users",
171 As: "bot",
172 }, func(items []interface{}) error {
173 streamedItems = append(streamedItems, items...)
174 return nil
175 }, PaginationOptions{})
176
177 if err != nil {
178 t.Fatalf("unexpected error: %v", err)
179 }
180 if !hasItems {
181 t.Error("expected hasItems=true for batch API")
182 }
183 if len(streamedItems) != 2 {
184 t.Errorf("expected 2 streamed items, got %d", len(streamedItems))
185 }
186 if !strings.Contains(errBuf.String(), "[pagination] streamed") {
187 t.Error("expected pagination summary log for batch API")
188 }
189 if result == nil {
190 t.Fatal("expected non-nil result")
191 }
192}
193
194func TestStreamPages_OnItemsErrorStopsPagination(t *testing.T) {
195 apiCalls := 0

Callers

nothing calls this directly

Calls 7

jsonResponseFunction · 0.85
newTestAPIClientFunction · 0.85
roundTripFuncFuncType · 0.70
StreamPagesMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected