Skip to content

test: add integration suite against real PostgreSQL and MySQL#1

Closed
Puppo wants to merge 2 commits into
masterfrom
test/integration-pg-mysql
Closed

test: add integration suite against real PostgreSQL and MySQL#1
Puppo wants to merge 2 commits into
masterfrom
test/integration-pg-mysql

Conversation

@Puppo

@Puppo Puppo commented Jun 10, 2026

Copy link
Copy Markdown
Owner

What

Adds a Docker-backed integration test suite that executes queries built by every public API of @nearform/sql against real PostgreSQL and MySQL. The existing tests only assert generated strings without ever running them, so regressions in placeholder numbering, identifier quoting, nested-statement offsets, or injection handling could pass CI while breaking real queries.

Coverage

11 cases × 3 drivers (pg, mysql2, legacy mysql) = 33 tests, all executed end-to-end:

  • Basic parameterized insert/select round-trip
  • Interpolated values stored as literals, not executed (injection)
  • glue — IN clause + batch insert
  • map — IN clause (default & object mapper)
  • quoteIdent — dynamic table/column names + escaping the quote char on a live identifier
  • unsafe — literal fragment interpolation
  • Nested SqlStatement — proves $N placeholder numbering against a live server
  • Deprecated append
  • Null values
  • Special characters / unicode round-trip

Changes

  • integration/ — config + driver adapters (one query/raw/end interface) + a single dialect-aware feature suite shared by all three drivers.
  • docker-compose.yml — add mysql:8.0 service with healthchecks, bump Postgres to 17-alpine.
  • package.json — add mysql/mysql2 devDeps and db:up, db:down, test:integration, test:integration:docker scripts.
  • .github/workflows/ci.yml — add MySQL service + integration test step.
  • README.md — document the new commands.

Notes

  • The legacy mysql driver can't speak MySQL 8's default caching_sha2_password, so the adapter uses a short mysql2 connection to switch the account to mysql_native_password first — works identically locally and in CI without a container command override (unsupported by GitHub service containers).
  • Integration tests run with --test-concurrency=1 because both MySQL drivers share one sqlmap database; the pg suite is isolated in its own DB.

Verification

  • All 33 integration tests pass against live Postgres + MySQL.
  • npm test (unit) still passes and needs no DB; npm run lint clean.
  • Regression check: deliberately broke the $N offset logic → nested-statement pg test failed as intended → reverted.

Run locally with npm run test:integration:docker.

Executes queries built by every public API (params, glue, map, quoteIdent,
unsafe, nested statements, append, nulls, special chars, injection-as-literal)
against live PostgreSQL and MySQL (both mysql and mysql2 drivers), proving the
generated SQL is valid and that interpolated values are stored as literals.

- docker-compose: add mysql:8.0 service + healthchecks, bump postgres to 17
- package.json: add mysql/mysql2 devDeps and db:up/db:down/test:integration scripts
- ci: add MySQL service and integration test step
- README: document the integration commands
@github-actions

Copy link
Copy Markdown

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

@Puppo

Puppo commented Jun 10, 2026

Copy link
Copy Markdown
Owner Author

Superseded by upstream PR nearform#236.

@Puppo Puppo closed this Jun 10, 2026
@Puppo Puppo deployed to production June 10, 2026 00:12 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant