mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
refactor: Update TestDatabase to use pg-mem for in-memory database in tests
This commit is contained in:
parent
99a80ab9b6
commit
01be73612d
@ -2,22 +2,24 @@ import PostgresDatabase, {
|
||||
DatabaseSource,
|
||||
DatabaseSourceOptions,
|
||||
} from "../../../Server/Infrastructure/PostgresDatabase";
|
||||
import { newDb } from "pg-mem";
|
||||
import { IMemoryDb, newDb } from "pg-mem";
|
||||
import logger from "../../../Server/Utils/Logger";
|
||||
import getTestDataSourceOptions from "../../../Server/Infrastructure/Postgres/TestDataSourceOptions";
|
||||
|
||||
export default class TestDatabase extends PostgresDatabase {
|
||||
public async createAndConnect(): Promise<void> {
|
||||
const testDatasourceOptions = getTestDataSourceOptions();
|
||||
const testDatasourceOptions: DatabaseSourceOptions = getTestDataSourceOptions();
|
||||
await this.connect(testDatasourceOptions);
|
||||
}
|
||||
|
||||
public override async connect(
|
||||
dataSourceOptions: DatabaseSourceOptions,
|
||||
): Promise<DatabaseSource> {
|
||||
const db = newDb();
|
||||
const db: IMemoryDb = newDb();
|
||||
const dataSource: DatabaseSource =
|
||||
db.adapters.createTypeormDataSource(dataSourceOptions);
|
||||
await dataSource.initialize();
|
||||
await dataSource.synchronize();
|
||||
logger.debug("Postgres Database Connected");
|
||||
this.dataSource = dataSource;
|
||||
return dataSource;
|
||||
|
Loading…
Reference in New Issue
Block a user