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
2018-03-07 11:15:00 -08:00

32 lines
632 B
Go

package defaults
import (
"bytes"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/pkg/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))
if !strings.Contains(b.String(), "error from (192.0.2.1:1234) /target: error occurred") {
t.Error("output was wrong:", b.String())
}
}