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

Function TestRecover

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

Source from the content-addressed store, hash-verified

16)
17
18func TestRecover(t *testing.T) {
19 e := echo.New()
20 buf := new(bytes.Buffer)
21 e.Logger = slog.New(&discardHandler{})
22 req := httptest.NewRequest(http.MethodGet, "/", nil)
23 rec := httptest.NewRecorder()
24 c := e.NewContext(req, rec)
25 h := Recover()(func(c *echo.Context) error {
26 panic("test")
27 })
28 err := h(c)
29 assert.Contains(t, err.Error(), "[PANIC RECOVER] test goroutine")
30
31 var pse *PanicStackError
32 if errors.As(err, &pse) {
33 assert.Contains(t, string(pse.Stack), "middleware/recover.go")
34 } else {
35 assert.Fail(t, "not of type PanicStackError")
36 }
37
38 assert.Equal(t, http.StatusOK, rec.Code) // status is still untouched. err is returned from middleware chain
39 assert.Contains(t, buf.String(), "") // nothing is logged
40}
41
42func TestRecover_skipper(t *testing.T) {
43 e := echo.New()

Callers

nothing calls this directly

Calls 4

RecoverFunction · 0.85
NewContextMethod · 0.80
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…