(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func 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 | |
| 49 | func TestBodyDump_skipper(t *testing.T) { |
| 50 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…