This directory contains SQL tests for the promscale extension. Tests must be written in SQL and
the usage of pgtap.sql
is highly encouraged.
Run the tests with cargo test -p sql-tests
. By default, the tests are run
against localhost:5432
. You can override it either by specifying
POSTGRES_URL
or a combination of POSTGRES_USER
, POSTGRES_HOST
, POSTGRES_PORT
and POSTGRES_DB
environment variables.
POSTGRES_URL=postgres://ubuntu@localhost:54321/ cargo test -p sql-tests
or
POSTGRES_USER=postgres POSTGRES_HOST=localhost POSTGRES_PORT=5432 cargo test -p sql-tests
To run the tests against a docker image set the value of the TS_DOCKER_IMAGE
to the desired docker image, e.g.:
TS_DOCKER_IMAGE=ghcr.io/timescale/dev_promscale_extension:master-ts2-pg13 cargo test -p sql-tests
Each .sql
file in the testdata
directory is executed as its own test, against a fresh database.
We provide two ways of testing: pgTAP tests, and snapshot tests. Snapshot tests are like golden tests:
when they break, it's often unclear why they broke, because the assertion is run over the whole test output.
Please write new tests as pgTAP tests, as these should be more robust.
If pgTAP is used in a test, then the output of the test run is parsed with our pgTAP parser. If any tests failed, the whole test run will fail.
To add a new pgTAP test:
- create new
.sql
file in thetestdata
directory - use pgTAP in your test file, see the existing pgTAP examples
- run the tests with
cargo test -p sql-tests
(see [Running tests][Running tests])
The output of the script is recorded as a snapshot, and compared on the next test run.
To add a new snapshot test:
0. (prerequisite) run cargo install cargo-insta
- create a new
.sql
file in thetestdata
directory - run the tests with
cargo test -p sql-tests
- the tests will fail
- validate that the new snapshot output is as you expect it to be
- run
cargo insta review
to interactively review the snapshot outputs (orcargo insta accept
to accept them all)