Skip to content

Commit

Permalink
test: Ensure pg client points to correct location during integration
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Mar 29, 2024
1 parent 2e75e03 commit 669fce5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions runner/src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ declare namespace NodeJS {
PGPASSWORD: string
PGDATABASE: string
PORT: string
CRON_DATABASE: string
}
}
18 changes: 15 additions & 3 deletions runner/src/provisioner/provisioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ export interface DatabaseConnectionParameters {
password: string
}

interface Config {
cronDatabase: string
// Allow overriding the default values for testing
postgresHost?: string
postgresPort?: number
}

const defaultConfig: Config = {
cronDatabase: process.env.CRON_DATABASE,
};

export default class Provisioner {
tracer: Tracer = trace.getTracer('queryapi-runner-provisioner');
#hasBeenProvisioned: Record<string, Record<string, boolean>> = {};
Expand All @@ -41,6 +52,7 @@ export default class Provisioner {
private readonly hasuraClient: HasuraClient = new HasuraClient(),
private readonly adminDefaultPgClient: PgClientClass = adminDefaultPgClientGlobal,
private readonly adminCronPgClient: PgClientClass = adminCronPgClientGlobal,
private readonly config: Config = defaultConfig,
private readonly crypto: typeof cryptoModule = cryptoModule,
private readonly pgFormat: typeof pgFormatLib = pgFormatLib,
private readonly PgClient: typeof PgClientClass = PgClientClass
Expand Down Expand Up @@ -96,9 +108,9 @@ export default class Provisioner {
const userCronPgClient = new this.PgClient({
user: userDbConnectionParameters.username,
password: userDbConnectionParameters.password,
database: CRON_DATABASE,
host: userDbConnectionParameters.host,
port: userDbConnectionParameters.port,
database: this.config.cronDatabase,
host: this.config.postgresHost ?? userDbConnectionParameters.host,
port: this.config.postgresPort ?? userDbConnectionParameters.port,
});

await userCronPgClient.query(
Expand Down

0 comments on commit 669fce5

Please sign in to comment.