Skip to content

Commit 8abb2ae

Browse files
committed
test(coderd/database/dbtestutil): allow access to *sql.DB
1 parent 1e75762 commit 8abb2ae

File tree

1 file changed

+10
-0
lines changed
  • coderd/database/dbtestutil

1 file changed

+10
-0
lines changed

coderd/database/dbtestutil/db.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func WillUsePostgres() bool {
3131
type options struct {
3232
fixedTimezone string
3333
dumpOnFailure bool
34+
returnSQLDB func(*sql.DB)
3435
}
3536

3637
type Option func(*options)
@@ -49,6 +50,12 @@ func WithDumpOnFailure() Option {
4950
}
5051
}
5152

53+
func WithReturnSQLDB(f func(*sql.DB)) Option {
54+
return func(o *options) {
55+
o.returnSQLDB = f
56+
}
57+
}
58+
5259
func NewDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub) {
5360
t.Helper()
5461

@@ -88,6 +95,9 @@ func NewDB(t testing.TB, opts ...Option) (database.Store, pubsub.Pubsub) {
8895
t.Cleanup(func() {
8996
_ = sqlDB.Close()
9097
})
98+
if o.returnSQLDB != nil {
99+
o.returnSQLDB(sqlDB)
100+
}
91101
if o.dumpOnFailure {
92102
t.Cleanup(func() { DumpOnFailure(t, connectionURL) })
93103
}

0 commit comments

Comments
 (0)