mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-01-01 14:19:18 +03:00
reset postgres and redis between test runs
This commit is contained in:
22
test/utils/reset.ts
Normal file
22
test/utils/reset.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// drop postgres tables
|
||||
// reset redis cache
|
||||
import { config } from "../../src/config";
|
||||
import { createClient } from "redis";
|
||||
import { Pool } from "pg";
|
||||
import { Logger } from "../../src/utils/logger";
|
||||
|
||||
export async function resetRedis() {
|
||||
if (config.redis) {
|
||||
const client = createClient(config.redis);
|
||||
await client.connect();
|
||||
await client.flushAll();
|
||||
}
|
||||
}
|
||||
export async function resetPostgres() {
|
||||
if (process.env.TEST_POSTGRES && config.postgres) {
|
||||
const pool = new Pool({ ...config.postgres });
|
||||
await pool.query(`DROP DATABASE IF EXISTS "sponsorTimes"`);
|
||||
await pool.query(`DROP DATABASE IF EXISTS "privateDB"`);
|
||||
await pool.end().catch(err => Logger.error(`closing db (postgres): ${err}`));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user