Skip to content

Commit e367768

Browse files
committed
fix: enhance postgres health check
Coming from docker-library/docs#2393 (comment)
1 parent e165a4d commit e367768

File tree

4 files changed

+261
-10
lines changed

4 files changed

+261
-10
lines changed

package-lock.json

Lines changed: 242 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
"@playwright/test": "^1.48.2",
2828
"@types/ms": "^0.7.34",
2929
"@types/node": "^22.8.5",
30+
"@types/pg": "^8.11.10",
3031
"@types/ws": "^8.5.12",
3132
"esbuild": "^0.24.0",
33+
"pg": "^8.13.1",
3234
"typescript": "^5.6.3"
3335
},
3436
"dependencies": {

src/postgres.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Postgres {
1010
imageName: 'postgres:latest',
1111
ports: [POSTGRES_PORT],
1212
healthcheck: {
13-
test: ['CMD-SHELL', 'pg_isready'],
13+
test: ['CMD-SHELL', 'pg_isready', `--username=${user}`, `--host=localhost`, `--port=${POSTGRES_PORT}`, `--dbname=${db}`],
1414
intervalMs: ms('1s'),
1515
retries: 10,
1616
startPeriodMs: 0,

tests/postgres.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { test } from '@playwright/test';
2+
import pg from 'pg';
3+
import { Postgres } from '../src/postgres.js';
4+
5+
test('should work', async ({}) => {
6+
const s = await Postgres.start({
7+
user: 'foo',
8+
password: 'bar',
9+
db: 'postgres',
10+
});
11+
const client = new pg.Client(s.connectOptions());
12+
await client.connect();
13+
await client.query('SELECT 1');
14+
await client.end();
15+
await s.stop();
16+
})

0 commit comments

Comments
 (0)