(t *testing.T)
| 537 | } |
| 538 | |
| 539 | func TestSimulateHTTP_NDJSONStreamMatchAndEarlyClose_319(t *testing.T) { |
| 540 | ctx := context.Background() |
| 541 | logger := zap.NewNop() |
| 542 | |
| 543 | serverClosed := make(chan struct{}) |
| 544 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 545 | w.Header().Set("Content-Type", "application/x-ndjson") |
| 546 | flusher, ok := w.(http.Flusher) |
| 547 | require.True(t, ok, "server response writer must support flushing") |
| 548 | |
| 549 | _, _ = w.Write([]byte("{\"id\":1,\"ok\":true}\n")) |
| 550 | flusher.Flush() |
| 551 | _, _ = w.Write([]byte("{\"id\":2,\"ok\":false}\n")) |
| 552 | flusher.Flush() |
| 553 | _, _ = w.Write([]byte("{\"id\":3,\"ok\":true}\n")) |
| 554 | flusher.Flush() |
| 555 | |
| 556 | <-r.Context().Done() |
| 557 | close(serverClosed) |
| 558 | })) |
| 559 | defer server.Close() |
| 560 | |
| 561 | expectedBody := "{\"id\":1,\"ok\":true}\n{\"id\":2,\"ok\":false}\n" |
| 562 | |
| 563 | tc := &models.TestCase{ |
| 564 | Name: "ndjson-match-and-close", |
| 565 | HTTPReq: models.HTTPReq{ |
| 566 | Method: "GET", |
| 567 | URL: server.URL, |
| 568 | }, |
| 569 | HTTPResp: models.HTTPResp{ |
| 570 | Header: map[string]string{ |
| 571 | "Content-Type": "application/x-ndjson", |
| 572 | }, |
| 573 | Body: expectedBody, |
| 574 | StreamBody: []models.HTTPStreamChunk{ |
| 575 | { |
| 576 | Data: []models.HTTPStreamDataField{ |
| 577 | {Key: "raw", Value: `{"id":1,"ok":true}`}, |
| 578 | }, |
| 579 | }, |
| 580 | { |
| 581 | Data: []models.HTTPStreamDataField{ |
| 582 | {Key: "raw", Value: `{"id":2,"ok":false}`}, |
| 583 | }, |
| 584 | }, |
| 585 | }, |
| 586 | }, |
| 587 | } |
| 588 | |
| 589 | // Use SimulateHTTPStreaming for streaming test cases |
| 590 | streamResp, err := SimulateHTTPStreaming(ctx, tc, "test-set", logger, SimulationConfig{APITimeout: 3}) |
| 591 | require.NoError(t, err) |
| 592 | require.NotNil(t, streamResp) |
| 593 | |
| 594 | // Compare the stream |
| 595 | noiseKeys := map[string]struct{}{} |
| 596 | matched, _, _, compareErr := CompareHTTPStream(tc.HTTPResp, streamResp.Reader, streamResp.StreamConfig, noiseKeys, logger) |
nothing calls this directly
no test coverage detected