File tree 1 file changed +16
-4
lines changed
coderd/database/dbtestutil
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -50,22 +50,34 @@ func WithDumpOnFailure() Option {
50
50
}
51
51
}
52
52
53
- func WithReturnSQLDB (f func (* sql.DB )) Option {
53
+ func withReturnSQLDB (f func (* sql.DB )) Option {
54
54
return func (o * options ) {
55
55
o .returnSQLDB = f
56
56
}
57
57
}
58
58
59
+ func NewDBWithSQLDB (t testing.TB , opts ... Option ) (database.Store , pubsub.Pubsub , * sql.DB ) {
60
+ t .Helper ()
61
+
62
+ if ! WillUsePostgres () {
63
+ t .Fatalf ("cannot use WithReturnSQLDB without PostgreSQL, consider adding `if !dbtestutil.WillUsePostgres() { t.Skip() }` to this test" )
64
+ }
65
+
66
+ var sqlDB * sql.DB
67
+ opts = append (opts , withReturnSQLDB (func (db * sql.DB ) {
68
+ sqlDB = db
69
+ }))
70
+ db , ps := NewDB (t , opts ... )
71
+ return db , ps , sqlDB
72
+ }
73
+
59
74
func NewDB (t testing.TB , opts ... Option ) (database.Store , pubsub.Pubsub ) {
60
75
t .Helper ()
61
76
62
77
var o options
63
78
for _ , opt := range opts {
64
79
opt (& o )
65
80
}
66
- if o .returnSQLDB && ! WillUsePostgres () {
67
- t .Fatalf ("cannot use WithReturnSQLDB without PostgreSQL, consider adding `if !dbtestutil.WillUsePostgres() { t.Skip() }` to this test" )
68
- }
69
81
70
82
db := dbfake .New ()
71
83
ps := pubsub .NewInMemory ()
You can’t perform that action at this time.
0 commit comments