// Package logging tests — behavioral tests for ServiceLogger. // Since ServiceLogger delegates to ja4common/logger.ComponentLogger, // we test behavior (no-panic, interface satisfaction, level filtering) // rather than internal output buffering. package logging_test import ( "testing" "github.com/antitbone/ja4/sentinel/api" "github.com/antitbone/ja4/sentinel/internal/logging" ) func TestNewServiceLogger_NonNil(t *testing.T) { logger := logging.NewServiceLogger("info") if logger == nil { t.Fatal("expected non-nil logger") } } func TestServiceLogger_ImplementsApiLogger(t *testing.T) { logger := logging.NewServiceLogger("debug") var _ api.Logger = logger // compile-time check } func TestServiceLogger_AllLevels_NoPanic(t *testing.T) { levels := []string{"debug", "info", "warn", "error", "invalid"} for _, level := range levels { t.Run(level, func(t *testing.T) { logger := logging.NewServiceLogger(level) logger.Debug("comp", "debug msg", map[string]string{"k": "v"}) logger.Info("comp", "info msg", nil) logger.Warn("comp", "warn msg", map[string]string{"x": "y"}) logger.Error("comp", "error msg", nil) }) } } func TestServiceLogger_WithDetails(t *testing.T) { logger := logging.NewServiceLogger("debug") details := map[string]string{"error": "test error", "trace_id": "abc123"} logger.Info("service", "test message", details) } func TestServiceLogger_NilDetails(t *testing.T) { logger := logging.NewServiceLogger("debug") logger.Info("service", "test message", nil) } func TestServiceLogger_ConcurrentLogging(t *testing.T) { logger := logging.NewServiceLogger("debug") done := make(chan bool) for i := 0; i < 10; i++ { go func(id int) { logger.Info("service", "concurrent message", map[string]string{"id": string(rune('0'+id))}) done <- true }(i) } for i := 0; i < 10; i++ { <-done } } func TestLoggerFactory(t *testing.T) { factory := &logging.LoggerFactory{} levels := []string{"debug", "info", "warn", "error"} for _, level := range levels { t.Run(level, func(t *testing.T) { logger := factory.NewLogger(level) if logger == nil { t.Fatalf("NewLogger(%q) returned nil", level) } }) } logger := factory.NewDefaultLogger() if logger == nil { t.Fatal("NewDefaultLogger() returned nil") } }