File tree Expand file tree Collapse file tree 4 files changed +40
-9
lines changed Expand file tree Collapse file tree 4 files changed +40
-9
lines changed Original file line number Diff line number Diff line change @@ -170,13 +170,21 @@ func (s *SqliteStore) ExecuteMigrations(target MigrationTarget) error {
170170func NewTestSqliteDB (t * testing.T ) * SqliteStore {
171171 t .Helper ()
172172
173- dbFileName := filepath .Join (t .TempDir (), "tmp.db" )
174- t .Logf ("Creating new SQLite DB for testing: %s" , dbFileName )
175-
176173 // TODO(roasbeef): if we pass :memory: for the file name, then we get
177174 // an in mem version to speed up tests
175+ dbPath := filepath .Join (t .TempDir (), "tmp.db" )
176+ t .Logf ("Creating new SQLite DB handle for testing: %s" , dbPath )
177+
178+ return NewTestSqliteDbHandleFromPath (t , dbPath )
179+ }
180+
181+ // NewTestSqliteDbHandleFromPath is a helper function that creates a SQLite
182+ // database handle given a database file path.
183+ func NewTestSqliteDbHandleFromPath (t * testing.T , dbPath string ) * SqliteStore {
184+ t .Helper ()
185+
178186 sqlDB , err := NewSqliteStore (& SqliteConfig {
179- DatabaseFileName : dbFileName ,
187+ DatabaseFileName : dbPath ,
180188 SkipMigrations : false ,
181189 })
182190 require .NoError (t , err )
Original file line number Diff line number Diff line change @@ -221,11 +221,8 @@ func (d *DbHandler) AddRandomServerAddrs(t *testing.T,
221221 return addrs
222222}
223223
224- // NewDbHandle creates a new store and query handle to the test database.
225- func NewDbHandle (t * testing.T ) * DbHandler {
226- // Create a new test database.
227- db := NewTestDB (t )
228-
224+ // newDbHandleFromDb creates a new database store handle given a database store.
225+ func newDbHandleFromDb (db * BaseDB ) * DbHandler {
229226 testClock := clock .NewTestClock (time .Now ())
230227
231228 // Gain a handle to the pending (minting) universe federation store.
@@ -268,3 +265,17 @@ func NewDbHandle(t *testing.T) *DbHandler {
268265 DirectQuery : db ,
269266 }
270267}
268+
269+ // NewDbHandleFromPath creates a new database store handle given a database file
270+ // path.
271+ func NewDbHandleFromPath (t * testing.T , dbPath string ) * DbHandler {
272+ db := NewTestDbHandleFromPath (t , dbPath )
273+ return newDbHandleFromDb (db .BaseDB )
274+ }
275+
276+ // NewDbHandle creates a new database store handle.
277+ func NewDbHandle (t * testing.T ) * DbHandler {
278+ // Create a new test database with the default database file path.
279+ db := NewTestDB (t )
280+ return newDbHandleFromDb (db .BaseDB )
281+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ func NewTestDB(t *testing.T) *PostgresStore {
1111 return NewTestPostgresDB (t )
1212}
1313
14+ // NewTestDbHandleFromPath is a helper function that creates a new handle to an
15+ // existing SQLite database for testing.
16+ func NewTestDbHandleFromPath (t * testing.T , dbPath string ) * PostgresStore {
17+ return NewTestPostgresDB (t )
18+ }
19+
1420// NewTestDBWithVersion is a helper function that creates a Postgres database
1521// for testing and migrates it to the given version.
1622func NewTestDBWithVersion (t * testing.T , version uint ) * PostgresStore {
Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ func NewTestDB(t *testing.T) *SqliteStore {
1111 return NewTestSqliteDB (t )
1212}
1313
14+ // NewTestDbHandleFromPath is a helper function that creates a new handle to an
15+ // existing SQLite database for testing.
16+ func NewTestDbHandleFromPath (t * testing.T , dbPath string ) * SqliteStore {
17+ return NewTestSqliteDbHandleFromPath (t , dbPath )
18+ }
19+
1420// NewTestDBWithVersion is a helper function that creates an SQLite database for
1521// testing and migrates it to the given version.
1622func NewTestDBWithVersion (t * testing.T , version uint ) * SqliteStore {
You can’t perform that action at this time.
0 commit comments