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)
| 906 | // ParseHTTPResponse, validating both success and failure cases for parsing raw |
| 907 | // HTTP data into their respective struct representations. |
| 908 | func 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: |
nothing calls this directly
no test coverage detected