mirror of
https://github.com/volatiletech/authboss.git
synced 2024-11-24 08:42:17 +02:00
32 lines
640 B
Go
32 lines
640 B
Go
package defaults
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"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))
|
|
|
|
if !strings.Contains(b.String(), "error from (192.0.2.1:1234) /target: error occurred") {
|
|
t.Error("output was wrong:", b.String())
|
|
}
|
|
}
|