MCPcopy
hub / github.com/labstack/echo / TestBodyDump_ResponseWithinLimit

Function TestBodyDump_ResponseWithinLimit

middleware/body_dump_test.go:316–341  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

314}
315
316func TestBodyDump_ResponseWithinLimit(t *testing.T) {
317 e := echo.New()
318 responseData := "Response data"
319 req := httptest.NewRequest(http.MethodGet, "/", nil)
320 rec := httptest.NewRecorder()
321 c := e.NewContext(req, rec)
322
323 h := func(c *echo.Context) error {
324 return c.String(http.StatusOK, responseData)
325 }
326
327 responseBodyDumped := ""
328 mw, err := BodyDumpConfig{
329 Handler: func(c *echo.Context, reqBody, resBody []byte, err error) {
330 responseBodyDumped = string(resBody)
331 },
332 MaxRequestBytes: 1 * MB,
333 MaxResponseBytes: 1 * MB,
334 }.ToMiddleware()
335 assert.NoError(t, err)
336
337 err = mw(h)(c)
338 assert.NoError(t, err)
339 assert.Equal(t, responseData, responseBodyDumped, "Small response should be fully dumped")
340 assert.Equal(t, responseData, rec.Body.String(), "Client should receive full response")
341}
342
343func TestBodyDump_ResponseExceedsLimit(t *testing.T) {
344 e := echo.New()

Callers

nothing calls this directly

Calls 3

StringMethod · 0.95
NewContextMethod · 0.80
ToMiddlewareMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…