pgsqlmock
pgsqlmock : Mocking and faking helpers for PostgreSQL unit tests
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3130 | pgsqlmock | pgsqlmock | 1.0.1 |
LANG | PostgreSQL | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| ----d-r | No | No | No | Yes | yes | no |
| Relationships | |
|---|---|
| Requires | plpgsql pgtap |
| See Also | faker dbt2 pg_mockable pgtap omni_test random tsm_system_time tsm_system_rows |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0.1 |
18 17 16 15 14 | pgsqlmock |
plpgsql, pgtap |
| RPM | PIGSTY | 1.0.1 |
18 17 16 15 14 | pgsqlmock_$v |
pgtap_$v |
| DEB | PIGSTY | 1.0.1 |
18 17 16 15 14 | postgresql-$v-pgsqlmock |
postgresql-$v-pgtap |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| el8.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| el9.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| el9.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| el10.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| el10.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| d12.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| d12.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| d13.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| d13.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| u22.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| u22.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| u24.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| u24.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| u26.x86_64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
| u26.aarch64 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 | PIGSTY 1.0.1 |
Source
github.com/v-maliutin/pgSQLMock
pgsqlmock-1.0.1.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
pgsqlmock extends pgTAP with table fakes, function and view mocks, call-count assertions, and debugging helpers. Its helpers alter or replace real database objects, so upstream requires using them inside pgTAP’s transaction-based test context, where the changes are rolled back after the test.
Fake Tables
fake_table(text[], ...) can isolate a test from foreign keys, primary keys, NOT NULL constraints, partitions, or pre-existing rows. Pass schema-qualified table names as a text[]:
Important options include make_table_empty, leave_primary_key, drop_not_null, drop_collation, and drop_partitions. Keeping a primary key while dropping the participating columns’ NOT NULL constraints is contradictory; remove or recreate the key explicitly for that test shape.
Mock Functions
mock_func(schema, name, signature, ...) temporarily replaces a routine while preserving its identity. Supply either a scalar value or SQL/prepared-statement text for a set result:
For set-returning routines, pass _return_set_value as a SQL query or the name of a prepared statement. Use get_routine_signature() when overloaded or defaulted arguments make the stored signature unclear.
Mock Views
mock_view(schema, view_name, return_set_sql) replaces a view with controlled rows:
Call Counts and Diagnostics
Set track_functions = 'all' before using call_count() to assert how often a routine was invoked:
print_table_as_json() and print_query_as_json() emit reproducible SQL/JSON-style snapshots through NOTICE, which is useful when pgTAP’s rollback would otherwise hide the state created during a failed test.
Caveats
- Run mocks and fakes only inside isolated test transactions; they issue real
ALTER,DROP, and replacement DDL. - pgSQLMock depends on PL/pgSQL and pgTAP. Load pgTAP before running its assertions.
call_count()depends on PostgreSQL function statistics and therefore requirestrack_functions = 'all'.- Release 1.0.1 fixes
fake_table()droppingNOT NULLconstraints on tables without a primary key.