|
1 | 1 | import pgPromise from 'pg-promise' |
2 | 2 |
|
3 | | -import { IS_TEST_ENV } from '@crowd/common' |
4 | | -import { DEFAULT_TENANT_ID } from '@crowd/common/src/env' |
| 3 | +import { DEFAULT_TENANT_ID, IS_TEST_ENV } from '@crowd/common' |
5 | 4 | import { type DbConnection, type DbInstance, type IDatabaseConfig } from '@crowd/database' |
6 | 5 | import type { QueryExecutor } from '@crowd/database' |
7 | 6 |
|
@@ -60,7 +59,7 @@ export async function resetTestDatabase(qx: QueryExecutor): Promise<void> { |
60 | 59 | const { name } = await qx.selectOne('SELECT current_database() AS name') |
61 | 60 |
|
62 | 61 | if (!/^test_[a-z0-9_]+$/.test(name)) { |
63 | | - throw new Error(`Not a worker test database: ${name}`) |
| 62 | + throw new Error(`Expected worker test database (got ${name})`) |
64 | 63 | } |
65 | 64 |
|
66 | 65 | await qx.selectNone(` |
@@ -137,21 +136,19 @@ async function dropDatabase(catalog: DbConnection, name: string): Promise<void> |
137 | 136 | */ |
138 | 137 | function getTestPostgres(): TestPostgres { |
139 | 138 | if (!IS_TEST_ENV) { |
140 | | - throw new Error(`NODE_ENV=test required (got ${process.env.NODE_ENV ?? 'unset'})`) |
| 139 | + throw new Error(`Expected NODE_ENV=test (got ${process.env.NODE_ENV ?? 'unset'})`) |
141 | 140 | } |
142 | 141 |
|
143 | 142 | const { DB_HOST: host, DB_PORT, DB_USER: user, DB_PASSWORD: password } = process.env |
144 | 143 |
|
145 | 144 | if (!host || !DB_PORT || !user || !password) { |
146 | | - throw new Error( |
147 | | - 'DB_HOST, DB_PORT, DB_USER, and DB_PASSWORD are required — run ./scripts/cli scaffold up-test and use .env.test', |
148 | | - ) |
| 145 | + throw new Error('Missing required database environment variables') |
149 | 146 | } |
150 | 147 |
|
151 | 148 | const port = Number(DB_PORT) |
152 | 149 |
|
153 | 150 | if (!['localhost', '127.0.0.1', '::1'].includes(host)) { |
154 | | - throw new Error(`Security safeguard: DB_HOST must be localhost (got: ${host})`) |
| 151 | + throw new Error(`Expected local DB_HOST (got ${host})`) |
155 | 152 | } |
156 | 153 |
|
157 | 154 | return { host, port, user, password } |
|
0 commit comments