1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-28 08:58:38 +02:00
authboss/defaults/error_handler_test.go

32 lines
640 B
Go
Raw Normal View History

package defaults
import (
"bytes"
"net/http"
"net/http/httptest"
"strings"
"testing"
2020-07-03 20:24:07 +02:00
"github.com/friendsofgo/errors"
)
func TestErrorHandler(t *testing.T) {
t.Parallel()
b := &bytes.Buffer{}
eh := ErrorHandler{LogWriter: NewLogger(b)}
handler := eh.Wrap(func(w http.ResponseWriter, r *http.Request) error {
return errors.New("error occurred")
})
// Assert that it's the right type
var _ http.Handler = handler
handler.ServeHTTP(nil, httptest.NewRequest("GET", "/target", nil))
2018-03-07 21:15:00 +02:00
if !strings.Contains(b.String(), "error from (192.0.2.1:1234) /target: error occurred") {
t.Error("output was wrong:", b.String())
}
}