(t *testing.T)
| 285 | } |
| 286 | |
| 287 | func TestBodyDump_RequestAtExactLimit(t *testing.T) { |
| 288 | e := echo.New() |
| 289 | exactData := strings.Repeat("B", 1024) |
| 290 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(exactData)) |
| 291 | rec := httptest.NewRecorder() |
| 292 | c := e.NewContext(req, rec) |
| 293 | |
| 294 | h := func(c *echo.Context) error { |
| 295 | body, _ := io.ReadAll(c.Request().Body) |
| 296 | return c.String(http.StatusOK, string(body)) |
| 297 | } |
| 298 | |
| 299 | requestBodyDumped := "" |
| 300 | limit := int64(1024) |
| 301 | mw, err := BodyDumpConfig{ |
| 302 | Handler: func(c *echo.Context, reqBody, resBody []byte, err error) { |
| 303 | requestBodyDumped = string(reqBody) |
| 304 | }, |
| 305 | MaxRequestBytes: limit, |
| 306 | MaxResponseBytes: 1 * MB, |
| 307 | }.ToMiddleware() |
| 308 | assert.NoError(t, err) |
| 309 | |
| 310 | err = mw(h)(c) |
| 311 | assert.NoError(t, err) |
| 312 | assert.Equal(t, int(limit), len(requestBodyDumped), "Exact limit should dump full data") |
| 313 | assert.Equal(t, exactData, requestBodyDumped) |
| 314 | } |
| 315 | |
| 316 | func TestBodyDump_ResponseWithinLimit(t *testing.T) { |
| 317 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…