2015-05-18 07:54:29 +02:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
2016-03-14 22:55:38 +02:00
|
|
|
"bytes"
|
2015-05-18 07:54:29 +02:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
2015-05-30 19:54:55 +02:00
|
|
|
|
|
|
|
"github.com/labstack/echo"
|
2016-01-29 09:46:11 +02:00
|
|
|
"github.com/labstack/echo/test"
|
2015-05-30 19:54:55 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2015-05-18 07:54:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRecover(t *testing.T) {
|
|
|
|
e := echo.New()
|
2016-03-14 22:55:38 +02:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
e.SetLogOutput(buf)
|
2016-04-24 19:21:23 +02:00
|
|
|
req := test.NewRequest(echo.GET, "/", nil)
|
|
|
|
rec := test.NewResponseRecorder()
|
|
|
|
c := e.NewContext(req, rec)
|
2016-02-18 07:49:31 +02:00
|
|
|
h := Recover()(echo.HandlerFunc(func(c echo.Context) error {
|
2015-05-18 07:54:29 +02:00
|
|
|
panic("test")
|
2016-02-15 18:11:29 +02:00
|
|
|
}))
|
2016-04-02 23:19:39 +02:00
|
|
|
h(c)
|
2016-04-24 19:21:23 +02:00
|
|
|
assert.Equal(t, http.StatusInternalServerError, rec.Status())
|
2016-03-14 22:55:38 +02:00
|
|
|
assert.Contains(t, buf.String(), "PANIC RECOVER")
|
2015-05-18 07:54:29 +02:00
|
|
|
}
|