1
0
mirror of https://github.com/labstack/echo.git synced 2025-05-29 23:17:34 +02:00
echo/middleware/recover_test.go
Vishal Rana 73fa05f826 Added panic recover middleware
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-05-17 22:54:29 -07:00

34 lines
657 B
Go

package middleware
import (
"github.com/labstack/echo"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestRecover(t *testing.T) {
e := echo.New()
e.Debug(true)
req, _ := http.NewRequest(echo.GET, "/", nil)
w := httptest.NewRecorder()
res := &echo.Response{Writer: w}
c := echo.NewContext(req, res, e)
h := func(c *echo.Context) *echo.HTTPError {
panic("test")
}
// Status
Recover()(h)(c)
if w.Code != http.StatusInternalServerError {
t.Errorf("expected status `500`, got %d.", w.Code)
}
// Body
s := w.Body.String()
if !strings.Contains(s, "panic recover") {
t.Error("expected body contains `panice recover`.")
}
}