Files
SnapOtter/tests/unit/docker/wait-for-postgres.test.ts
T
SnapOtterandGitHub 4ba7503f15 fix(docker): harden Postgres readiness checks in compose and startup (#595)
Pin the compose Postgres healthchecks to POSTGRES_DB (pg_isready was
defaulting to the username, silently reporting healthy while spamming
FATAL logs when USER and DB differ), and make docker/wait-for-postgres.mjs
log the target host and error code instead of a silent retry loop. Adds a
change-me note next to the default password in README and Docker Hub.

Refs #592
2026-07-21 14:01:02 +08:00

28 lines
1.1 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const here = dirname(fileURLToPath(import.meta.url));
const script = resolve(here, "../../../docker/wait-for-postgres.mjs");
function runProbe(databaseUrl: string) {
return spawnSync(process.execPath, [script], {
env: { ...process.env, DATABASE_URL: databaseUrl },
encoding: "utf8",
timeout: 15_000,
});
}
describe("wait-for-postgres probe", () => {
it("names the unreachable target instead of failing silently", () => {
// `.invalid` never resolves (RFC 2606), so the probe fails fast rather than
// waiting for a real host. The point of the fix is that the container log
// now says which host:port could not be reached (DNS failure, refused
// connection, or timeout) instead of just "Waiting for Postgres..." forever.
const res = runProbe("postgres://user:pass@snapotter-db-nope.invalid:5432/snapotter");
expect(res.status).toBe(1);
expect(res.stderr).toContain("snapotter-db-nope.invalid:5432");
});
});