Files
memby/server/internal/api/logging_test.go
T
2026-07-29 15:26:55 +12:00

37 lines
984 B
Go

package api
import (
"log/slog"
"net/http"
"testing"
)
func TestRequestLogLevel(t *testing.T) {
tests := []struct {
path string
status int
want slog.Level
}{
{"/healthz", http.StatusOK, slog.LevelDebug},
{"/v1/status", http.StatusOK, slog.LevelDebug},
{"/v1/images/123/primary", http.StatusOK, slog.LevelDebug},
{"/v1/home", http.StatusOK, slog.LevelInfo},
{"/v1/images/123/primary", http.StatusNotFound, slog.LevelWarn},
{"/v1/home", http.StatusServiceUnavailable, slog.LevelError},
}
for _, test := range tests {
if got := requestLogLevel(test.path, test.status); got != test.want {
t.Errorf("requestLogLevel(%q, %d) = %v, want %v", test.path, test.status, got, test.want)
}
}
}
func TestClientLogValueIsNeverBlank(t *testing.T) {
if got := clientLogValue(""); got != "unknown" {
t.Fatalf("blank identity logged as %q", got)
}
if got := clientLogValue("0.1.60"); got != "0.1.60" {
t.Fatalf("reported identity changed to %q", got)
}
}