Files
logging/middleware/request_logger_test.go
T
argoyle 8ff83ae37c
logging / test (push) Has been skipped
logging / vulnerabilities (push) Has been skipped
feat: initial shared logging module
slog SetupLogger (text/json/otel), context logger helpers, MockLogger test
helper, and a request-logger HTTP middleware sub-package. Replaces the logging
package + middleware request-logger copied across the backend services.
2026-06-15 11:52:40 +02:00

27 lines
650 B
Go

package middleware
import (
"log/slog"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRequestLogger(t *testing.T) {
called := false
h := RequestLogger(slog.New(slog.NewTextHandler(nil, nil)))(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called = true
w.WriteHeader(http.StatusCreated)
_, _ = w.Write([]byte("ok"))
}))
req := httptest.NewRequest(http.MethodPost, "/q", strings.NewReader("body"))
rw := httptest.NewRecorder()
h.ServeHTTP(rw, req)
assert.True(t, called)
assert.Equal(t, http.StatusCreated, rw.Code)
assert.Equal(t, "ok", rw.Body.String())
}