(t *testing.T)
| 163 | } |
| 164 | |
| 165 | func TestBodyDump_ReadError(t *testing.T) { |
| 166 | e := echo.New() |
| 167 | |
| 168 | // Create a reader that fails during read |
| 169 | failingReader := &failingReadCloser{ |
| 170 | data: []byte("partial data"), |
| 171 | failAt: 7, // Fail after 7 bytes |
| 172 | failWith: errors.New("connection reset"), |
| 173 | } |
| 174 | |
| 175 | req := httptest.NewRequest(http.MethodPost, "/", failingReader) |
| 176 | rec := httptest.NewRecorder() |
| 177 | c := e.NewContext(req, rec) |
| 178 | |
| 179 | h := func(c *echo.Context) error { |
| 180 | // This handler should not be reached if body read fails |
| 181 | body, _ := io.ReadAll(c.Request().Body) |
| 182 | return c.String(http.StatusOK, string(body)) |
| 183 | } |
| 184 | |
| 185 | requestBodyReceived := "" |
| 186 | mw := BodyDump(func(c *echo.Context, reqBody, resBody []byte, err error) { |
| 187 | requestBodyReceived = string(reqBody) |
| 188 | }) |
| 189 | |
| 190 | err := mw(h)(c) |
| 191 | |
| 192 | // Verify error is propagated |
| 193 | assert.Error(t, err) |
| 194 | assert.Contains(t, err.Error(), "connection reset") |
| 195 | |
| 196 | // Verify handler was not executed (callback wouldn't have received data) |
| 197 | assert.Empty(t, requestBodyReceived) |
| 198 | } |
| 199 | |
| 200 | // failingReadCloser is a helper type for testing read errors |
| 201 | type failingReadCloser struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…