mirror of
https://github.com/volatiletech/authboss.git
synced 2024-11-28 08:58:38 +02:00
32 lines
632 B
Go
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())
|
|
}
|
|
}
|