Skip to content

Commit

Permalink
Add idempotency test of RegisterTxDb
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Nov 1, 2024
1 parent 722239b commit c540333
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/pg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import (

func NewSqlxDB(t testing.TB, dbURL string) *sqlx.DB {
tests.SkipShortDB(t)

err := RegisterTxDb(dbURL)
if err != nil {
t.Errorf("failed to register txdb dialect: %w", err)
t.Errorf("failed to register txdb dialect: %s", err.Error())
return nil
}
db, err := sqlx.Open(string(TransactionWrappedPostgres), uuid.New().String())
Expand Down
7 changes: 7 additions & 0 deletions pkg/pg/txdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ import (
// See heavyweight.FullTestDB() as a convenience function to help you do this,
// but please use sparingly because as it's name implies, it is expensive.
func RegisterTxDb(dbURL string) error {
drivers := sql.Drivers()
for _, driver := range drivers {
if driver == string(TransactionWrappedPostgres) {
// TxDB driver already registered
return nil
}
}
testing.Init()
if !flag.Parsed() {
flag.Parse()
Expand Down

0 comments on commit c540333

Please sign in to comment.