Skip to content

Commit 4faeaa5

Browse files
author
Evan Phyillaier
committed
Add a Postgres test harness and a two-backend CI matrix
Testcontainers locally, a service container in CI, and a per-test-file database so the 19 db-touching suites cannot see each other's rows. The matrix exists because we ship two backends: a SQLite driver that CI never exercises would drift from the Postgres one, and dialect drift is the bug class that loses data. Locally, the only container runtime available is rootless Podman (no docker binary), so pg-global.js points DOCKER_HOST at the Podman socket and disables Ryuk when the developer hasn't already set either - Testcontainers then works unmodified on Docker or Podman. Ryuk's absence makes teardown() the only thing that stops/removes the container; StartedTestContainer#stop() removes volumes too, so no reaper is required as long as teardown runs. No Postgres driver exists yet (that's Task 4), so tests/harness.test.js is the only suite that actually exercises TEST_DATABASE_URL right now - the other 452 tests hardcode DB_PATH=':memory:' and keep running against SQLite regardless of TEST_BACKEND.
1 parent 8e02d50 commit 4faeaa5

8 files changed

Lines changed: 2534 additions & 100 deletions

File tree

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Tests
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
fail-fast: false
8+
matrix:
9+
backend: [pg, sqlite]
10+
services:
11+
postgres:
12+
image: postgres:16
13+
env:
14+
POSTGRES_PASSWORD: postgres
15+
POSTGRES_USER: postgres
16+
POSTGRES_DB: postgres
17+
ports: ['5432:5432']
18+
options: >-
19+
--health-cmd pg_isready --health-interval 10s
20+
--health-timeout 5s --health-retries 5
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
- run: npm ci
27+
- run: npm test
28+
env:
29+
TEST_BACKEND: ${{ matrix.backend }}
30+
TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,46 @@ npm run dev
175175

176176
Visit the client dev server's printed URL (usually `http://localhost:5173`).
177177

178+
## Running the tests
179+
180+
```bash
181+
npm test # Postgres backend (default) - boots a throwaway container
182+
npm run test:sqlite # SQLite backend, no container needed
183+
npm run test:all # both, sqlite then pg
184+
```
185+
186+
The Postgres backend needs a container runtime that speaks the Docker API.
187+
`tests/setup/pg-global.js` boots one shared Postgres 16 container via
188+
[Testcontainers](https://node.testcontainers.org) and each test file carves
189+
out its own database from it (`tests/helpers/backend.js`), so files can't
190+
see each other's rows.
191+
192+
- **Docker**: works out of the box, nothing to configure.
193+
- **Podman** (what this repo's containers were validated against; no
194+
`docker` binary required): start the user socket once per login session
195+
and Testcontainers will find it automatically -
196+
`tests/setup/pg-global.js` points `DOCKER_HOST` at the Podman socket
197+
itself if `DOCKER_HOST` isn't already set, so no per-developer config is
198+
needed:
199+
200+
```bash
201+
systemctl --user start podman.socket
202+
```
203+
204+
Rootless Podman can't grant Testcontainers' Ryuk reaper the privileges it
205+
wants, so the harness also sets `TESTCONTAINERS_RYUK_DISABLED=true` by
206+
default when using Podman. With Ryuk off, the container is stopped and
207+
removed by `teardown()` in `pg-global.js` at the end of the run instead -
208+
if a run is killed hard enough to skip that (e.g. `SIGKILL`), clean up any
209+
leftovers with `podman ps -a` / `podman rm -f`.
210+
- **CI** sets `TEST_DATABASE_URL` directly against a Postgres service
211+
container (see `.github/workflows/test.yml`) and never touches
212+
Testcontainers at all.
213+
214+
To point manually at a different runtime or disable Ryuk yourself, set
215+
`DOCKER_HOST` and/or `TESTCONTAINERS_RYUK_DISABLED` before running the
216+
tests - the harness only fills these in when they're unset.
217+
178218
## Live Events
179219

180220
At most one event is active globally at a time. Each is a set of tunable

0 commit comments

Comments
 (0)