Skip to content

Move the database tests into a nested dbtest module so go.mod requires no other module - #34

Merged
avgvi merged 1 commit into
masterfrom
test/nested-db-module
Oct 19, 2026
Merged

avgvi merged 1 commit into
masterfrom
test/nested-db-module

Conversation

@avgvi

@avgvi avgvi commented Oct 19, 2026

Copy link
Copy Markdown
Member

sqlx's go.mod listed go-sql-driver/mysql, lib/pq and go-sqlite3 because the tests imported them. Go's minimum version selection carries those requirements into every program that imports sqlx, so a consumer pinned to mysql v1.7.1 was silently raised to v1.10.1 by adopting the fork (upstream issues 642, 569 and 849 ask for this).

What moves

  • The tests that talk to a database move to dbtest/, a nested module with its own go.mod (the three drivers, plus replace github.com/secondwindoss/sqlx => ../). Whole files move with git mv; sqlx_test.go, sqlx_context_test.go, named_test.go and in_empty_test.go are split by declaration, copied verbatim.
  • dbtest is package dbtest with a dot import of sqlx, so the moved tests read as before.
  • The unit tests, benchmarks and compile-time interface checks that use unexported identifiers stay in the root (sqlx_unit_test.go, named_test.go, in_empty_test.go), with the fuzz, golden, scan, reflectx and types tests.
  • Three tests read the unexported unsafe field; they now check its effect instead: an unsafe Stmt scans into a struct that lacks selected columns, a safe one returns a missing destination error. TestUsage uses db.Select instead of the unexported scanAll (same code path).

Result

  • Root go.mod: module and go 1.24.0, no requirements; root go.sum is gone. A new lint step fails if the root module ever requires anything again.
  • CI vets, staticchecks and govulnchecks both modules, runs the root unit tests, then the database tests in dbtest/ against Postgres 16, MySQL 8 and SQLite (the Disabling check still applies). Dependabot watches /dbtest. Makefile, CONTRIBUTING, README and CHANGELOG updated.

Verified locally (Go 1.27.1, Postgres 16 and MySQL 8 in Docker, SQLite)

  • master: 335 pass, 2 skip. This branch: 296 pass in the root plus 39 pass and 2 skip in dbtest. The sets of test names are identical.
  • vet, staticcheck -checks=all, goimports and govulncheck clean on both modules.
  • A consumer module that pins mysql v1.7.1 and depends on this branch keeps v1.7.1; its go.mod change is only the sqlx lines.

@avgvi
avgvi merged commit ba75d3d into master Oct 19, 2026
10 checks passed
@avgvi
avgvi deleted the test/nested-db-module branch October 19, 2026 05:09
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