MCPcopy
hub / github.com/keploy/keploy / TestParseHTTPRequest_And_Response_111

Function TestParseHTTPRequest_And_Response_111

pkg/util_test.go:908–945  ·  view source on GitHub ↗

TestParseHTTPRequest_And_Response_111 contains sub-tests for ParseHTTPRequest and ParseHTTPResponse, validating both success and failure cases for parsing raw HTTP data into their respective struct representations.

(t *testing.T)

Source from the content-addressed store, hash-verified

906// ParseHTTPResponse, validating both success and failure cases for parsing raw
907// HTTP data into their respective struct representations.
908func TestParseHTTPRequest_And_Response_111(t *testing.T) {
909 t.Run("ParseHTTPRequest_Valid", func(t *testing.T) {
910 rawReq := "GET /test HTTP/1.1\r\nHost: example.com\r\n\r\n"
911 req, err := ParseHTTPRequest([]byte(rawReq))
912 require.NoError(t, err)
913 assert.Equal(t, "GET", req.Method)
914 assert.Equal(t, "/test", req.URL.Path)
915 assert.Equal(t, "example.com", req.Host)
916 })
917
918 t.Run("ParseHTTPRequest_Invalid", func(t *testing.T) {
919 rawReq := "this is not a valid request"
920 _, err := ParseHTTPRequest([]byte(rawReq))
921 require.Error(t, err)
922 })
923
924 t.Run("ParseHTTPResponse_Valid", func(t *testing.T) {
925 rawResp := "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHello, world!"
926 req, _ := http.NewRequest("GET", "http://example.com", nil)
927 resp, err := ParseHTTPResponse([]byte(rawResp), req)
928 require.NoError(t, err)
929 defer func() {
930 if err := resp.Body.Close(); err != nil {
931 t.Logf("failed to close response body: %v", err)
932 }
933 }()
934 assert.Equal(t, 200, resp.StatusCode)
935 body, _ := io.ReadAll(resp.Body)
936 assert.Equal(t, "Hello, world!", string(body))
937 })
938
939 t.Run("ParseHTTPResponse_Invalid", func(t *testing.T) {
940 rawResp := "this is not a valid response"
941 req, _ := http.NewRequest("GET", "http://example.com", nil)
942 _, err := ParseHTTPResponse([]byte(rawResp), req)
943 require.Error(t, err)
944 })
945}
946
947// TestCompressDecompress_AllEncodings_555 provides comprehensive testing for the
948// Compress and Decompress functions. It checks:

Callers

nothing calls this directly

Calls 5

ParseHTTPRequestFunction · 0.85
ParseHTTPResponseFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected