nix: Add postgrest-with-* tools to run with temporary databases of different versions

This commit is contained in:
Wolfgang Walther
2021-01-04 23:14:44 +01:00
committed by Remo Rechkemmer
parent 522308217a
commit ab6f90aa78
5 changed files with 107 additions and 72 deletions
+6 -10
View File
@@ -200,30 +200,26 @@ jobs:
when: on_fail
- run:
name: Run the spec tests against PostgreSQL 9.5
command: postgrest-test-spec-postgresql-9.5
command: postgrest-with-postgresql-9.5 postgrest-test-spec
when: always
- run:
name: Run the spec tests against PostgreSQL 9.6
command: postgrest-test-spec-postgresql-9.6
command: postgrest-with-postgresql-9.6 postgrest-test-spec
when: always
- run:
name: Run the spec tests against PostgreSQL 10
command: postgrest-test-spec-postgresql-10
command: postgrest-with-postgresql-10 postgrest-test-spec
when: always
- run:
name: Run the spec tests against PostgreSQL 11
command: postgrest-test-spec-postgresql-11
command: postgrest-with-postgresql-11 postgrest-test-spec
when: always
- run:
name: Run the spec tests against PostgreSQL 12
command: postgrest-test-spec-postgresql-12
command: postgrest-with-postgresql-12 postgrest-test-spec
when: always
- run:
name: Run the spec tests against PostgreSQL 13
command: postgrest-test-spec-postgresql-13
when: always
- run:
name: Check the spec tests for idempotence
name: Check the spec tests for idempotence against PostgreSQL 13
command: postgrest-test-spec-idempotence
when: always
- run:
+28 -16
View File
@@ -73,12 +73,15 @@ The PostgREST utilities available in `nix-shell` all have names that begin with
```bash
# Note: The utilities listed here might not be up to date.
[nix-shell]$ postgrest-<tab>
postgrest-lint postgrest-test-spec-postgresql-11
postgrest-style postgrest-test-spec-postgresql-12
postgrest-style-check postgrest-test-spec-postgresql-13
postgrest-test-spec postgrest-test-spec-postgresql-9.5
postgrest-test-spec-all postgrest-test-spec-postgresql-9.6
postgrest-test-spec-postgresql-10
postgrest-build postgrest-test-spec
postgrest-check postgrest-watch
postgrest-clean postgrest-with-all
postgrest-coverage postgrest-with-postgresql-10
postgrest-lint postgrest-with-postgresql-11
postgrest-run postgrest-with-postgresql-12
postgrest-style postgrest-with-postgresql-13
postgrest-style-check postgrest-with-postgresql-9.5
postgrest-test-io postgrest-with-postgresql-9.6
...
[nix-shell]$
@@ -94,12 +97,16 @@ is not used. You can activate those by passing a flag to `nix-shell` with
```bash
$ nix-shell --arg memoryTests true
[nix-shell]$ postgrest-<tab>
postgrest-lint postgrest-test-spec-postgresql-10
postgrest-style postgrest-test-spec-postgresql-11
postgrest-style-check postgrest-test-spec-postgresql-12
postgrest-test-memory postgrest-test-spec-postgresql-13
postgrest-test-spec postgrest-test-spec-postgresql-9.5
postgrest-test-spec-all postgrest-test-spec-postgresql-9.6
postgrest-build postgrest-test-spec
postgrest-check postgrest-watch
postgrest-clean postgrest-with-all
postgrest-coverage postgrest-with-postgresql-10
postgrest-lint postgrest-with-postgresql-11
postgrest-run postgrest-with-postgresql-12
postgrest-style postgrest-with-postgresql-13
postgrest-style-check postgrest-with-postgresql-9.5
postgrest-test-io postgrest-with-postgresql-9.6
postgrest-test-memory
...
```
@@ -156,11 +163,11 @@ temporary test databases:
$ nix-shell --run postgrest-test-spec
# Run the tests against all supported versions of PostgreSQL:
$ nix-shell --run postgrest-test-spec-all
$ nix-shell --run "postgrest-with-all postgrest-test-spec"
# Run the tests against a specific version of PostgreSQL (use tab-completion in
# nix-shell to see all available versions):
$ nix-shell --run postgrest-test-spec-postgresql-13
$ nix-shell --run "postgrest-with-postgresql-13 postgrest-test-spec"
```
@@ -202,9 +209,14 @@ Tools like `postgrest-build`, `postgrest-run` etc. are simple wrappers around
also run in CI, with the exception of the IO and Memory checks that need to be run
separately.
`postgrest-with-postgresql-*` take a command as an argument and will run it
with a temporary database. `postgrest-with-all` will run the command against
all supported PostgreSQL versions. Tests run without `postgrest-with-*` are
run against the latest PostgreSQL version by default.
`postgrest-watch` takes a command as an argument that it will re-run if any source
file is changed. For example, `postgrest-watch postgrest-test-spec-all` will re-run
the full spec test suite against all PostgreSQL versions on every change.
file is changed. For example, `postgrest-watch postgrest-with-all postgrest-test-spec`
will re-run the full spec test suite against all PostgreSQL versions on every change.
## Tour
+1 -1
View File
@@ -90,7 +90,7 @@ let
inRootDir = true;
}
''
${tests}/bin/postgrest-test-spec-all
${tests}/bin/postgrest-with-all ${tests}/bin/postgrest-test-spec
${tests}/bin/postgrest-test-spec-idempotence
${tests}/bin/postgrest-test-io
${style}/bin/postgrest-lint
+65 -45
View File
@@ -30,42 +30,84 @@ let
inRootDir = true;
}
''
export PATH=${postgresql}/bin:"$PATH"
# avoid starting multiple layers of with_tmp_db
if test ! -v PGRST_DB_URI; then
export PATH=${postgresql}/bin:"$PATH"
exec test/with_tmp_db "$@"
exec test/with_tmp_db "$@"
else
"$@"
fi
'';
# Script to run the Haskell test suite against a specific version of
# PostgreSQL.
# Create a `withPostgresql` for each PostgreSQL version that we want to test
# against.
withPostgresqlVersions =
builtins.map
({ name, postgresql }:
(checkedShellScript
{
name = "postgrest-with-${name}";
docs = "Run the given command in a temporary database with ${name}";
inRootDir = false;
}
''
${withTmpDb postgresql} "$@"
''
).bin
)
postgresqlVersions;
# Helper script for running a command against all PostgreSQL versions.
withAllVersions =
name:
let
runners =
builtins.map
({ name, postgresql }:
''
cat << EOF
Running against ${name}...
EOF
trap 'echo "Failed on ${name}"' exit
${withTmpDb postgresql} "$@"
trap "" exit
cat << EOF
Done running against ${name}.
EOF
'')
postgresqlVersions;
in
checkedShellScript
{
inherit name;
docs = "Run command against all supported PostgreSQL versions.";
inRootDir = true;
}
(lib.concatStringsSep "\n\n" runners);
# Script to run the Haskell test suite
testSpec =
name: postgresql:
checkedShellScript
{
inherit name;
docs = "Run the Haskell test suite against ${postgresql.name}.";
docs = "Run the Haskell test suite";
inRootDir = true;
}
''
env="$(cat ${postgrest.env})"
export PATH="$env/bin:$PATH"
cat << EOF
Running spec against ${postgresql.name}...
EOF
trap 'echo "Failed on ${postgresql.name}"' exit
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
trap "" exit
cat << EOF
Done running spec against ${postgresql.name}.
EOF
'';
testSpecIdempotence =
@@ -85,28 +127,6 @@ let
${cabal-install}/bin/cabal v2-test ${devCabalOptions}"
'';
# Create a `testSpec` for each PostgreSQL version that we want to test
# against.
testSpecVersions =
builtins.map
({ name, postgresql }:
(testSpec "postgrest-test-spec-${name}" postgresql).bin)
postgresqlVersions;
# Helper script for running the tests against all PostgreSQL versions.
testSpecAllVersions =
let
testRunners =
map (test: "${test}/bin/${test.name}") testSpecVersions;
in
checkedShellScript
{
name = "postgrest-test-spec-all";
docs = "Run the Haskell tests against all supported PostgreSQL versions.";
inRootDir = true;
}
(lib.concatStringsSep "\n" testRunners);
ioTestPython =
python3.withPackages (ps: [
ps.pyjwt
@@ -262,12 +282,12 @@ buildEnv
[
(testSpec "postgrest-test-spec" postgresql).bin
(testSpecIdempotence "postgrest-test-spec-idempotence" postgresql).bin
testSpecAllVersions.bin
(testIO "postgrest-test-io" postgresql).bin
(dumpSchema "postgrest-dump-schema" postgresql).bin
(coverage "postgrest-coverage" postgresql).bin
(coverageDraftOverlay "postgrest-coverage-draft-overlay").bin
] ++ testSpecVersions;
(withAllVersions "postgrest-with-all").bin
] ++ withPostgresqlVersions;
}
# The memory tests have large dependencies (a profiled build of PostgREST)
# and are run less often than the spec tests, so we don't include them in
+7
View File
@@ -40,6 +40,13 @@ lib.overrideDerivation postgrest.env (
''
source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh
complete -F _command postgrest-watch
complete -F _command postgrest-with-all
complete -F _command postgrest-with-postgresql-13
complete -F _command postgrest-with-postgresql-12
complete -F _command postgrest-with-postgresql-11
complete -F _command postgrest-with-postgresql-10
complete -F _command postgrest-with-postgresql-9.6
complete -F _command postgrest-with-postgresql-9.5
'';
}
)