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>
28 lines
632 B
Go
28 lines
632 B
Go
package dbxtest
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"git.codelab.vc/pkg/dbx"
|
|
)
|
|
|
|
// RunInTx executes fn inside a transaction that is always rolled back.
|
|
// This is useful for tests that modify data but should not leave side effects.
|
|
// The callback receives a dbx.Querier (not pgx.Tx) so it is compatible with
|
|
// InjectQuerier/ExtractQuerier patterns.
|
|
func RunInTx(t testing.TB, c *dbx.Cluster, fn func(ctx context.Context, q dbx.Querier)) {
|
|
t.Helper()
|
|
|
|
ctx := context.Background()
|
|
tx, err := c.Begin(ctx)
|
|
if err != nil {
|
|
t.Fatalf("dbxtest.RunInTx: begin: %v", err)
|
|
}
|
|
defer func() {
|
|
_ = tx.Rollback(ctx)
|
|
}()
|
|
|
|
fn(ctx, tx)
|
|
}
|