mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
13ac746093
Signed-off-by: Vishal Rana <vr@labstack.com>
34 lines
644 B
Go
34 lines
644 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.SetDebug(true)
|
|
req, _ := http.NewRequest(echo.GET, "/", nil)
|
|
w := httptest.NewRecorder()
|
|
res := echo.NewResponse(w)
|
|
c := echo.NewContext(req, res, e)
|
|
h := func(c *echo.Context) error {
|
|
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`.")
|
|
}
|
|
}
|