-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import MysqlStorage from '../../src/storage/mysql-storage.js'; | ||
import { | ||
expect, | ||
} from 'chai'; | ||
import 'mocha'; | ||
import storageFactory from '../../src/storage/storage-factory'; | ||
import getDatabase from '@databases/mysql-test'; | ||
import NoopStorage from '../../src/storage/noop-storage'; | ||
import delay from '../delay'; | ||
|
||
const WAIT_LONG = 25000; | ||
const WAIT_MEDIUM = 1000; | ||
const RADIX = 10; | ||
|
||
describe('storage/storage-factory', () => { | ||
it('should be a function', () => { | ||
expect(storageFactory,).to.be.a('function',); | ||
},); | ||
it('(mysql) should not throw an error', async() => { | ||
const database: { | ||
databaseURL: string; | ||
kill: () => Promise<void>; | ||
} = await getDatabase.default({ | ||
mysqlUser: 'idrinth-api-bench', | ||
mysqlPassword: 'mysqlTestPassword', | ||
mysqlDb: 'idrinth-api-bench', | ||
containerName: 'storage-factory-mysql', | ||
defaultExternalPort: 3338, | ||
},); | ||
const port = Number.parseInt( | ||
database.databaseURL.replace(/\D/gui, '',), | ||
RADIX, | ||
); | ||
const storage = storageFactory({ | ||
databaseUser: 'idrinth-api-bench', | ||
databasePassword: 'mysqlTestPassword', | ||
databaseDatabase: 'idrinth-api-bench', | ||
databasePort: port, | ||
database: 'mysql', | ||
cwd: '', | ||
task: 'bench', | ||
},) as MysqlStorage; | ||
expect(storage,).to.be.an.instanceof(MysqlStorage,); | ||
await delay(WAIT_MEDIUM,); | ||
storage.close(); | ||
await database.kill(); | ||
},).timeout(WAIT_LONG,); | ||
it('(noop) should not throw an error', function() { | ||
const storage = storageFactory({ | ||
cwd: '', | ||
task: 'bench', | ||
},); | ||
expect(storage,).to.be.an.instanceof(NoopStorage,); | ||
},); | ||
},); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import MysqlStorage from './mysql-storage.js'; | ||
import PostgresStorage from './postgres-storage.js'; | ||
import MssqlStorage from './mssql-storage.js'; | ||
import NoopStorage from './noop-storage.js'; | ||
import Config from '../cli/config/config.js'; | ||
import Storage from './storage.js'; | ||
|
||
// eslint-disable-next-line complexity | ||
export default (config: Config,): Storage => { | ||
switch (config.database) { | ||
case 'mysql': | ||
return new MysqlStorage( | ||
config.databaseHost, | ||
config.databasePassword, | ||
config.databasePort, | ||
config.databaseUser ?? 'idrinth-api-bench', | ||
config.databaseDatabase ?? 'idrinth-api-bench', | ||
); | ||
case 'postgres': | ||
return new PostgresStorage( | ||
config.databaseHost, | ||
config.databasePassword, | ||
config.databasePort, | ||
config.databaseUser ?? 'idrinth-api-bench', | ||
config.databaseDatabase ?? 'idrinth-api-bench', | ||
); | ||
case 'mssql': | ||
return new MssqlStorage( | ||
config.databaseHost, | ||
config.databasePassword, | ||
config.databasePort, | ||
config.databaseDriver, | ||
config.databaseUser ?? 'idrinth-api-bench', | ||
config.databaseDatabase ?? 'idrinth-api-bench', | ||
config.databaseTrustedConnection === 'true', | ||
); | ||
default: | ||
if (config.database) { | ||
throw new Error(`Database type ${ config.database } is unknown.`,); | ||
} | ||
return new NoopStorage(); | ||
} | ||
}; |