Some checks failed
CI / test (push) Failing after 13s
- slog.go: SlogLogger adapts *slog.Logger to dbx.Logger interface - scan.go: Collect[T] and CollectOne[T] generic helpers using pgx.RowToStructByName - cluster.go: slow query logging via Config.SlowQueryThreshold (Warn level in queryEnd) - stats.go: PoolStats with Cluster.Stats() aggregating pool stats across all nodes - config.go/node.go: NodeConfig.Tracer passthrough for pgx.QueryTracer (OpenTelemetry) - options.go: WithSlowQueryThreshold and WithTracer functional options - dbxtest/tx.go: RunInTx runs callback in always-rolled-back transaction for test isolation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
989 B
Go
53 lines
989 B
Go
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")
|
|
}
|