2015-05-18 07:54:29 +02:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
2015-05-30 19:54:55 +02:00
|
|
|
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2015-05-18 07:54:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRecover(t *testing.T) {
|
|
|
|
e := echo.New()
|
2015-09-13 19:03:20 +02:00
|
|
|
e.SetDebug(true)
|
2015-05-18 07:54:29 +02:00
|
|
|
req, _ := http.NewRequest(echo.GET, "/", nil)
|
2015-05-30 19:54:55 +02:00
|
|
|
rec := httptest.NewRecorder()
|
2015-12-01 21:22:45 +02:00
|
|
|
c := echo.NewContext(req, echo.NewResponse(rec, e), e)
|
2015-05-20 23:38:51 +02:00
|
|
|
h := func(c *echo.Context) error {
|
2015-05-18 07:54:29 +02:00
|
|
|
panic("test")
|
|
|
|
}
|
|
|
|
Recover()(h)(c)
|
2015-05-30 19:54:55 +02:00
|
|
|
assert.Equal(t, http.StatusInternalServerError, rec.Code)
|
|
|
|
assert.Contains(t, rec.Body.String(), "panic recover")
|
2015-05-18 07:54:29 +02:00
|
|
|
}
|