forked from OneUptime/oneuptime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
should generate a string of random numbers of specified length
- Loading branch information
Showing
5 changed files
with
30 additions
and
35 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
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 |
---|---|---|
@@ -1,33 +1,16 @@ | ||
import PostgresDatabase, { | ||
DatabaseSource, | ||
DatabaseSourceOptions, | ||
} from "../../../Server/Infrastructure/PostgresDatabase"; | ||
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: DatabaseSourceOptions = getTestDataSourceOptions(); | ||
await this.connect(testDatasourceOptions); | ||
} | ||
public override getDatasourceOptions(): DatabaseSourceOptions { | ||
if (this.dataSourceOptions) { | ||
return this.dataSourceOptions; | ||
} | ||
|
||
public override async connect( | ||
dataSourceOptions: DatabaseSourceOptions, | ||
): Promise<DatabaseSource> { | ||
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; | ||
} | ||
this.dataSourceOptions = getTestDataSourceOptions(); | ||
|
||
public async disconnectAndDropDatabase(): Promise<void> { | ||
// Drop the database. Since this is the in-mem db, it will be destroyed. | ||
return this.dataSourceOptions; | ||
} | ||
} | ||
|
||
export const PostgresAppInstance: TestDatabase = new TestDatabase(); |
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