github.com/volatiletech/authboss@v2.4.1+incompatible/defaults/error_handler_test.go (about)

     1  package defaults
     2  
     3  import (
     4  	"bytes"
     5  	"net/http"
     6  	"net/http/httptest"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/pkg/errors"
    11  )
    12  
    13  func TestErrorHandler(t *testing.T) {
    14  	t.Parallel()
    15  
    16  	b := &bytes.Buffer{}
    17  
    18  	eh := ErrorHandler{LogWriter: NewLogger(b)}
    19  
    20  	handler := eh.Wrap(func(w http.ResponseWriter, r *http.Request) error {
    21  		return errors.New("error occurred")
    22  	})
    23  	// Assert that it's the right type
    24  	var _ http.Handler = handler
    25  
    26  	handler.ServeHTTP(nil, httptest.NewRequest("GET", "/target", nil))
    27  
    28  	if !strings.Contains(b.String(), "error from (192.0.2.1:1234) /target: error occurred") {
    29  		t.Error("output was wrong:", b.String())
    30  	}
    31  }