Implement pgTAP subset for SQL-level testing of go-postgres #2
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
go-postgres translates PostgreSQL syntax to SQLite. There's no SQL-level test framework to verify that the translation behaves correctly. Currently all testing is done from Go, which doesn't exercise the SQL surface the way a user would.
pgTAP is the standard PostgreSQL SQL testing framework (~143 functions), but it requires PL/pgSQL and PostgreSQL extensions — neither available in pglike/SQLite.
Proposal
Implement a small pgTAP-compatible subset as Go-native functions registered in the SQL engine. This gives us SQL-level tests that can run against both go-postgres and real PostgreSQL to verify compatibility.
Minimum useful subset (~20-30 functions)
Infrastructure:
plan(),no_plan(),finish(),diag()Core assertions:
ok(),is(),isnt(),pass(),fail()Result testing:
results_eq(),is_empty()Schema checks:
has_table(),has_column(),col_type_is(),col_not_null()Skip/todo:
skip(),todo(),todo_end()Implementation approach
has_table,has_column, etc.) are justSELECTqueries againstinformation_schema— straightforwardcmp_ok()andthrows_ok()initially — they require dynamic SQL (EXECUTE).sqlthat run identically against pglike and real PostgreSQLWhat this does NOT include
cmp_ok,throws_ok)Value
CockroachDB note
CockroachDB has no equivalent SQL testing framework. If go-postgres supports pgTAP subset, the same tests could potentially validate CockroachDB compatibility too (CockroachDB has partial PL/pgSQL since v23.2 but lacks
EXECUTE).Migrated from Codeberg: originally #2, opened 2026-03-17.
Update: v0.4.0 changes the picture
go-postgres switched to ncruces/sqlite in v0.4.0, which supports registering custom Go scalar and aggregate functions directly in SQLite. This makes the implementation approach much more concrete:
Revised implementation approach
plan(),ok(),is(),diag()etc. become Go functions callable from SQLhas_table,has_column) queriessqlite_masterbut presents pgTAP-compatible signaturesWhat's now easier
Remaining considerations
results_eq()needs to execute two queries and compare — may need to be a Go-side helper rather than a pure SQL functionplan,ok,is,isnt,finish,diag), schema checks second(hum3, 2026-03-18)