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) }