(t *testing.T)
| 152 | } |
| 153 | |
| 154 | func 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 | |
| 194 | func TestStreamPages_OnItemsErrorStopsPagination(t *testing.T) { |
| 195 | apiCalls := 0 |
nothing calls this directly
no test coverage detected