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

Function TestBodyDump

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

Source from the content-addressed store, hash-verified

16)
17
18func TestBodyDump(t *testing.T) {
19 e := echo.New()
20 hw := "Hello, World!"
21 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(hw))
22 rec := httptest.NewRecorder()
23 c := e.NewContext(req, rec)
24 h := func(c *echo.Context) error {
25 body, err := io.ReadAll(c.Request().Body)
26 if err != nil {
27 return err
28 }
29 return c.String(http.StatusOK, string(body))
30 }
31
32 requestBody := ""
33 responseBody := ""
34 mw, err := BodyDumpConfig{Handler: func(c *echo.Context, reqBody, resBody []byte, err error) {
35 requestBody = string(reqBody)
36 responseBody = string(resBody)
37 }}.ToMiddleware()
38 assert.NoError(t, err)
39
40 if assert.NoError(t, mw(h)(c)) {
41 assert.Equal(t, requestBody, hw)
42 assert.Equal(t, responseBody, hw)
43 assert.Equal(t, http.StatusOK, rec.Code)
44 assert.Equal(t, hw, rec.Body.String())
45 }
46
47}
48
49func TestBodyDump_skipper(t *testing.T) {
50 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…