| 22 | } |
| 23 | |
| 24 | func OpenPreparedTestDB(ctx context.Context, dbURL string) (*pgxpool.Pool, error) { |
| 25 | if dbURL == "" { |
| 26 | dbURL = defaultTestDBURL |
| 27 | } |
| 28 | |
| 29 | pool, err := pgxpool.New(ctx, dbURL) |
| 30 | if err != nil { |
| 31 | return nil, err |
| 32 | } |
| 33 | |
| 34 | if err := pool.Ping(ctx); err != nil { |
| 35 | pool.Close() |
| 36 | return nil, err |
| 37 | } |
| 38 | |
| 39 | if err := runMigrations(ctx, pool); err != nil { |
| 40 | pool.Close() |
| 41 | return nil, err |
| 42 | } |
| 43 | |
| 44 | if err := truncateAll(ctx, pool); err != nil { |
| 45 | pool.Close() |
| 46 | return nil, err |
| 47 | } |
| 48 | |
| 49 | return pool, nil |
| 50 | } |
| 51 | |
| 52 | func TestDB(t *testing.T) *pgxpool.Pool { |
| 53 | t.Helper() |