MCPcopy Index your code
hub / github.com/labstack/echo / TestBodyDump_RequestAtExactLimit

Function TestBodyDump_RequestAtExactLimit

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

Source from the content-addressed store, hash-verified

285}
286
287func 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
316func TestBodyDump_ResponseWithinLimit(t *testing.T) {
317 e := echo.New()

Callers

nothing calls this directly

Calls 4

RequestMethod · 0.95
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…