chore: code review

Signed-off-by: blam <ben@blam.sh>

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-11-29 09:40:58 +01:00
parent bc4ae198ef
commit ed5abc4340
2 changed files with 29 additions and 0 deletions
@@ -163,6 +163,31 @@ describe('postgres', () => {
});
});
it('should throw with incorrect config', async () => {
await expect(
buildPgDatabaseConfig(
new ConfigReader({
client: 'pg',
connection: {
type: 'cloudsql',
},
}),
),
).rejects.toThrow(/Missing instance connection name for Cloud SQL/);
await expect(
buildPgDatabaseConfig(
new ConfigReader({
client: 'not-pg',
connection: {
type: 'cloudsql',
instance: 'asd:asd:asd',
},
}),
),
).rejects.toThrow(/Cloud SQL only supports the pg client/);
});
it('adds the settings from cloud-sql-connector', async () => {
const { Connector } = jest.requireMock(
'@google-cloud/cloud-sql-connector',
@@ -78,6 +78,10 @@ export async function buildPgDatabaseConfig(
);
if (config.connection?.type === 'cloudsql') {
if (config.client !== 'pg') {
throw new Error('Cloud SQL only supports the pg client');
}
if (!config.connection.instance) {
throw new Error('Missing instance connection name for Cloud SQL');
}