logginghandler/logginghandler_test.go

31 lines
622 B
Go
Raw Normal View History

2020-10-13 15:26:40 +02:00
package logginghandler_test
import (
"context"
"log"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
2021-01-18 11:02:17 +01:00
"go.xsfx.dev/logginghandler"
2020-10-13 15:26:40 +02:00
)
func testHandler(w http.ResponseWriter, r *http.Request) {
log.Print("got request")
}
func TestUUID(t *testing.T) {
assert := assert.New(t)
req, err := http.NewRequestWithContext(context.Background(), "GET", "/test", nil)
assert.NoError(err)
rr := httptest.NewRecorder()
handler := logginghandler.Handler(http.HandlerFunc(testHandler))
handler.ServeHTTP(rr, req)
assert.NotEmpty(rr.Header().Get("X-Request-ID"))
log.Print(rr.Header())
}