MCPcopy
hub / github.com/keploy/keploy / TestSimulateHTTP_PlainTextStreamMatchAndEarlyClose_321

Function TestSimulateHTTP_PlainTextStreamMatchAndEarlyClose_321

pkg/util_test.go:706–781  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

704}
705
706func TestSimulateHTTP_PlainTextStreamMatchAndEarlyClose_321(t *testing.T) {
707 ctx := context.Background()
708 logger := zap.NewNop()
709
710 serverClosed := make(chan struct{})
711 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
712 w.Header().Set("Content-Type", "text/plain")
713 flusher, ok := w.(http.Flusher)
714 require.True(t, ok, "server response writer must support flushing")
715
716 _, _ = w.Write([]byte("[INFO] booting\n"))
717 flusher.Flush()
718 _, _ = w.Write([]byte("[INFO] ready\n"))
719 flusher.Flush()
720 _, _ = w.Write([]byte("[INFO] keep-running\n"))
721 flusher.Flush()
722
723 <-r.Context().Done()
724 close(serverClosed)
725 }))
726 defer server.Close()
727
728 expectedBody := "[INFO] booting\n[INFO] ready\n"
729
730 tc := &models.TestCase{
731 Name: "plain-stream-match-and-close",
732 HTTPReq: models.HTTPReq{
733 Method: "GET",
734 URL: server.URL,
735 },
736 HTTPResp: models.HTTPResp{
737 Header: map[string]string{
738 "Content-Type": "text/plain",
739 },
740 Body: expectedBody,
741 StreamBody: []models.HTTPStreamChunk{
742 {
743 Data: []models.HTTPStreamDataField{
744 {Key: "raw", Value: "[INFO] booting"},
745 },
746 },
747 {
748 Data: []models.HTTPStreamDataField{
749 {Key: "raw", Value: "[INFO] ready"},
750 },
751 },
752 },
753 },
754 }
755
756 // Use SimulateHTTPStreaming for streaming test cases
757 streamResp, err := SimulateHTTPStreaming(ctx, tc, "test-set", logger, SimulationConfig{APITimeout: 3})
758 require.NoError(t, err)
759 require.NotNil(t, streamResp)
760
761 // Compare the stream
762 noiseKeys := map[string]struct{}{}
763 matched, _, _, compareErr := CompareHTTPStream(tc.HTTPResp, streamResp.Reader, streamResp.StreamConfig, noiseKeys, logger)

Callers

nothing calls this directly

Calls 6

SimulateHTTPStreamingFunction · 0.85
CompareHTTPStreamFunction · 0.85
FlushMethod · 0.80
WriteMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected