|
1 | 1 | There are basically two types of tests you can add:
|
2 | 2 |
|
3 | 3 | - pgTAP based tests, and
|
| 4 | +- pg\_regress tests |
4 | 5 | - Migration tests.
|
5 | 6 |
|
6 |
| -In both cases, a number of extensions may be installed into the database for |
| 7 | +In all cases, a number of extensions may be installed into the database for |
7 | 8 | use; you can see those in both [postgresql.conf.in](../tests/postgresql.conf.in)
|
8 | 9 | and [prime.sql](../tests/prime.sql) (extensions may be enabled in either place.)
|
9 | 10 |
|
| 11 | +## pg\_regress tests |
| 12 | + |
| 13 | +pg\_regress tests are in [tests/sql](./../tests/sql/) with output in [tests/expected](./../tests/expected/). |
| 14 | +To create a new test, create a new SQL file in [tests/sql](./../tests/sql/) and then run: |
| 15 | + |
| 16 | +``` |
| 17 | +nix flake check -L |
| 18 | +``` |
| 19 | + |
| 20 | +Next, review the logs to identify where the test output was written |
| 21 | + |
| 22 | +``` |
| 23 | +postgres> CREATE EXTENSION IF NOT EXISTS index_advisor; |
| 24 | +postgres> CREATE EXTENSION |
| 25 | +postgres> (using postmaster on localhost, port 5432) |
| 26 | +postgres> ============== running regression test queries ============== |
| 27 | +postgres> test new_test ... diff: /nix/store/5gk419ddz7mzzwhc9j6yj5i8lkw67pdl-tests/expected/new_test.out: No such file or directory |
| 28 | +postgres> diff command failed with status 512: diff "/nix/store/5gk419ddz7mzzwhc9j6yj5i8lkw67pdl-tests/expected/new_test.out" "/nix/store/2fbrvnnr7iz6yigyf0rb0vxnyqvrgxzp-postgres-15.6-check-harness/regression_output/results/new_test.out" > "/nix/store/2fbrvnnr7iz6yigyf0rb0vxnyqvrgxzp-postgres-15.6-check-harness/regression_output/results/new_test.out.diff |
| 29 | +``` |
| 30 | + |
| 31 | +and copy the `regression_output` directory to where you can review |
| 32 | + |
| 33 | +``` |
| 34 | +cp -r /nix/store/2fbrvnnr7iz6yigyf0rb0vxnyqvrgxzp-postgres-15.6-check-harness/regression_output . |
| 35 | +``` |
| 36 | + |
| 37 | +Then you can review the contents of `regression_output/results/new_test.out` to see if it matches what you expected. |
| 38 | + |
| 39 | +If it does match your expectations, copy the file to [tests/expected](./../tests/expected/) and the test will pass on the next run. |
| 40 | + |
| 41 | +If the output does not match your expectations, update the `<new_test>.sql` file, re-run with `nix flake check -L` and try again |
| 42 | + |
| 43 | + |
10 | 44 | ## pgTAP tests
|
11 | 45 |
|
12 | 46 | These are super easy: simply add `.sql` files to the
|
|
0 commit comments