executeBatch handles batch request scenarios
(t *testing.T, scenario Scenario)
| 366 | |
| 367 | // executeBatch handles batch request scenarios |
| 368 | func (e *executor) executeBatch(t *testing.T, scenario Scenario) { |
| 369 | t.Helper() |
| 370 | |
| 371 | // Batch requests only work with HTTP |
| 372 | require.Equal(t, TransportHTTP, scenario.Transport, "Batch requests only supported on HTTP transport") |
| 373 | |
| 374 | ctx := context.Background() |
| 375 | client, err := harness.NewClient(e.serverURL, nil) |
| 376 | require.NoError(t, err, "Failed to create client") |
| 377 | |
| 378 | // Build batch request |
| 379 | batch := make([]any, 0, len(scenario.Batch)) |
| 380 | for _, req := range scenario.Batch { |
| 381 | method := req.GetMethod(scenario.Method) |
| 382 | jsonReq := map[string]any{ |
| 383 | "jsonrpc": "2.0", |
| 384 | "method": method, |
| 385 | "params": req.Params, |
| 386 | } |
| 387 | if req.ID != nil { |
| 388 | jsonReq["id"] = req.ID |
| 389 | } |
| 390 | batch = append(batch, jsonReq) |
| 391 | } |
| 392 | |
| 393 | // Send batch |
| 394 | batchJSON, err := json.Marshal(batch) |
| 395 | require.NoError(t, err, "Failed to marshal batch") |
| 396 | |
| 397 | responseJSON, err := client.CallHTTPRaw(ctx, batchJSON) |
| 398 | require.NoError(t, err, "Batch call failed") |
| 399 | |
| 400 | // Parse batch response |
| 401 | var responses []json.RawMessage |
| 402 | err = json.Unmarshal(responseJSON, &responses) |
| 403 | require.NoError(t, err, "Failed to parse batch response") |
| 404 | |
| 405 | // Validate responses |
| 406 | require.Len(t, responses, len(scenario.ExpectBatch), "Response count mismatch") |
| 407 | |
| 408 | for i, respJSON := range responses { |
| 409 | var resp map[string]any |
| 410 | err := json.Unmarshal(respJSON, &resp) |
| 411 | require.NoErrorf(t, err, "Failed to parse response %d", i) |
| 412 | |
| 413 | e.validateBatchResponse(t, i, resp, scenario.ExpectBatch[i]) |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | // executeRaw handles raw request scenarios |
| 418 | func (e *executor) executeRaw(t *testing.T, scenario Scenario) { |
no test coverage detected