(t *testing.T)
| 225 | } |
| 226 | |
| 227 | func TestBodyDump_RequestWithinLimit(t *testing.T) { |
| 228 | e := echo.New() |
| 229 | requestData := "Hello, World!" |
| 230 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(requestData)) |
| 231 | rec := httptest.NewRecorder() |
| 232 | c := e.NewContext(req, rec) |
| 233 | |
| 234 | h := func(c *echo.Context) error { |
| 235 | body, _ := io.ReadAll(c.Request().Body) |
| 236 | return c.String(http.StatusOK, string(body)) |
| 237 | } |
| 238 | |
| 239 | requestBodyDumped := "" |
| 240 | mw, err := BodyDumpConfig{ |
| 241 | Handler: func(c *echo.Context, reqBody, resBody []byte, err error) { |
| 242 | requestBodyDumped = string(reqBody) |
| 243 | }, |
| 244 | MaxRequestBytes: 1 * MB, // 1MB limit |
| 245 | MaxResponseBytes: 1 * MB, |
| 246 | }.ToMiddleware() |
| 247 | assert.NoError(t, err) |
| 248 | |
| 249 | err = mw(h)(c) |
| 250 | assert.NoError(t, err) |
| 251 | assert.Equal(t, requestData, requestBodyDumped, "Small request should be fully dumped") |
| 252 | assert.Equal(t, requestData, rec.Body.String(), "Handler should receive full request") |
| 253 | } |
| 254 | |
| 255 | func TestBodyDump_RequestExceedsLimit(t *testing.T) { |
| 256 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…