File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 22# chinook database is used in non-destructive tests
33CHINOOK_DATABASE_URL = " sqlitecloud://user:password@xxx.sqlite.cloud:8860/chinook.db"
44
5- # testing database is used in destructive tests
5+ # testing databases are also created automatically as testing-xxx.db and used in destructive tests
66TESTING_DATABASE_URL = " sqlitecloud://user:password@xxx.sqlite.cloud:8860/testing.db"
Original file line number Diff line number Diff line change @@ -13,12 +13,16 @@ import {
1313 getChinookConnection ,
1414 WARN_SPEED_MS ,
1515 EXPECT_SPEED_MS ,
16- EXTRA_LONG_TIMEOUT
16+ clearTestingDatabasesAsync
1717} from './shared'
1818
1919describe ( 'connection' , ( ) => {
2020 let chinook : SQLiteCloudConnection
2121
22+ beforeAll ( async ( ) => {
23+ await clearTestingDatabasesAsync ( )
24+ } )
25+
2226 beforeEach ( ( ) => {
2327 chinook = getChinookConnection ( )
2428 } )
Original file line number Diff line number Diff line change @@ -145,6 +145,26 @@ export async function getTestingDatabaseAsync(): Promise<Database> {
145145 return database
146146}
147147
148+ /** Drop databases that are no longer in use */
149+ export async function clearTestingDatabasesAsync ( ) {
150+ const chinook = getChinookDatabase ( )
151+
152+ let numDeleted = 0
153+ let databases = await chinook . sql `LIST DATABASES;`
154+ const testingPattern = / ^ t e s t i n g - \d { 16 } \. d b $ /
155+ for ( let i = 0 ; i < databases . length ; i ++ ) {
156+ const databaseName = databases [ i ] [ 'name' ]
157+ if ( testingPattern . test ( databaseName ) ) {
158+ const result = await chinook . sql `REMOVE DATABASE ${ databaseName } ;`
159+ console . assert ( result )
160+ numDeleted ++
161+ }
162+ }
163+ if ( numDeleted > 0 ) {
164+ console . log ( `Deleted ${ numDeleted } testing databases` )
165+ }
166+ }
167+
148168//
149169// more utilities
150170//
You can’t perform that action at this time.
0 commit comments