2018-11-14 09:18:03 +00:00
|
|
|
package recovery
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRecoverHandler(t *testing.T) {
|
|
|
|
fn := func(w http.ResponseWriter, r *http.Request) {
|
2022-02-21 11:40:09 +00:00
|
|
|
panic("I love panicking!")
|
2018-11-14 09:18:03 +00:00
|
|
|
}
|
2021-01-21 09:04:04 +00:00
|
|
|
recovery, err := New(context.Background(), http.HandlerFunc(fn))
|
2018-11-14 09:18:03 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
server := httptest.NewServer(recovery)
|
|
|
|
defer server.Close()
|
|
|
|
|
|
|
|
resp, err := http.Get(server.URL)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
|
|
|
}
|