MCPcopy
hub / github.com/keploy/keploy / TestSimulateHTTP_MultipartStreamMatchAndEarlyClose_320

Function TestSimulateHTTP_MultipartStreamMatchAndEarlyClose_320

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

Source from the content-addressed store, hash-verified

614}
615
616func TestSimulateHTTP_MultipartStreamMatchAndEarlyClose_320(t *testing.T) {
617 ctx := context.Background()
618 logger := zap.NewNop()
619 const boundary = "myCustomBoundary"
620
621 writePart := func(w http.ResponseWriter, contentType string, body string) {
622 _, _ = w.Write([]byte("--" + boundary + "\r\n"))
623 _, _ = w.Write([]byte("Content-Type: " + contentType + "\r\n\r\n"))
624 _, _ = w.Write([]byte(body))
625 _, _ = w.Write([]byte("\r\n"))
626 }
627
628 serverClosed := make(chan struct{})
629 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
630 w.Header().Set("Content-Type", "multipart/x-mixed-replace; boundary="+boundary)
631 flusher, ok := w.(http.Flusher)
632 require.True(t, ok, "server response writer must support flushing")
633
634 writePart(w, "application/json", `{"frame":1}`)
635 flusher.Flush()
636 writePart(w, "text/plain", "frame-2")
637 flusher.Flush()
638 writePart(w, "text/plain", "frame-3")
639 flusher.Flush()
640
641 <-r.Context().Done()
642 close(serverClosed)
643 }))
644 defer server.Close()
645
646 expectedBody := strings.Join([]string{
647 "--" + boundary,
648 "Content-Type: application/json",
649 "",
650 `{"frame":1}`,
651 "--" + boundary,
652 "Content-Type: text/plain",
653 "",
654 "frame-2",
655 "",
656 }, "\r\n")
657
658 tc := &models.TestCase{
659 Name: "multipart-match-and-close",
660 HTTPReq: models.HTTPReq{
661 Method: "GET",
662 URL: server.URL,
663 },
664 HTTPResp: models.HTTPResp{
665 Header: map[string]string{
666 "Content-Type": "multipart/x-mixed-replace; boundary=" + boundary,
667 },
668 Body: expectedBody,
669 StreamBody: []models.HTTPStreamChunk{
670 {
671 Data: []models.HTTPStreamDataField{
672 {Key: "raw", Value: expectedBody},
673 },

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