package dbx import ( "bytes" "context" "log/slog" "strings" "testing" ) func TestSlogLogger(t *testing.T) { var buf bytes.Buffer h := slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug}) l := NewSlogLogger(slog.New(h)) ctx := context.Background() l.Debug(ctx, "debug msg", "key", "val1") l.Info(ctx, "info msg", "key", "val2") l.Warn(ctx, "warn msg", "key", "val3") l.Error(ctx, "error msg", "key", "val4") out := buf.String() for _, want := range []string{ "level=DEBUG", "debug msg", "key=val1", "level=INFO", "info msg", "key=val2", "level=WARN", "warn msg", "key=val3", "level=ERROR", "error msg", "key=val4", } { if !strings.Contains(out, want) { t.Errorf("output missing %q\ngot: %s", want, out) } } } func TestNewSlogLoggerNil(t *testing.T) { l := NewSlogLogger(nil) if l.Logger == nil { t.Fatal("expected non-nil logger when passing nil") } // should not panic l.Info(context.Background(), "test") }