nix(refactor): Move withPostgresqlVersions and withAllVersions to new withTools

This commit is contained in:
Wolfgang Walther
2021-04-18 13:51:39 +02:00
committed by Wolfgang Walther
parent dccce946e3
commit 32bac81d91
6 changed files with 97 additions and 95 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ jobs:
cachix use postgrest
- run:
name: Install testing scripts
command: nix-env -f default.nix -iA tests tests.memoryTests
command: nix-env -f default.nix -iA tests tests.memoryTests withTools
- run:
name: Run coverage (io tests and spec tests against PostgreSQL 13)
command: postgrest-coverage
+3 -3
View File
@@ -112,13 +112,13 @@ rec {
nixpkgsUpgrade =
pkgs.callPackage nix/nixpkgs-upgrade.nix { };
withTmpDb =
pkgs.callPackage nix/withtmpdb.nix { };
withTools =
pkgs.callPackage nix/withtools.nix { inherit postgresqlVersions; };
# Scripts for running tests.
tests =
pkgs.callPackage nix/tests.nix {
inherit postgrest postgrestProfiled postgresqlVersions devCabalOptions withTmpDb;
inherit postgrest postgrestProfiled devCabalOptions withTools;
ghc = pkgs.haskell.compiler."${compiler}";
hpc-codecov = pkgs.haskell.packages."${compiler}".hpc-codecov;
};
+9 -67
View File
@@ -10,71 +10,14 @@
, gnugrep
, haskell
, hpc-codecov
, lib
, postgresql
, postgresqlVersions
, postgrest
, postgrestProfiled
, python3
, runtimeShell
, withTmpDb
, withTools
, yq
}:
let
# 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 =
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
{
name = "postgrest-with-all";
docs = "Run command against all supported PostgreSQL versions.";
inRootDir = true;
}
(lib.concatStringsSep "\n\n" runners);
# Script to run the Haskell test suite
testSpec =
checkedShellScript
{
@@ -86,7 +29,7 @@ let
env="$(cat ${postgrest.env})"
export PATH="$env/bin:$PATH"
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
${withTools.latest} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
'';
testSpecIdempotence =
@@ -100,7 +43,7 @@ let
env="$(cat ${postgrest.env})"
export PATH="$env/bin:$PATH"
${withTmpDb postgresql} ${runtimeShell} -c " \
${withTools.latest} ${runtimeShell} -c " \
${cabal-install}/bin/cabal v2-test ${devCabalOptions} && \
${cabal-install}/bin/cabal v2-test ${devCabalOptions}"
'';
@@ -127,7 +70,7 @@ let
export PATH="$env/bin:$PATH"
${cabal-install}/bin/cabal v2-build ${devCabalOptions}
${cabal-install}/bin/cabal v2-exec ${withTmpDb postgresql} \
${cabal-install}/bin/cabal v2-exec ${withTools.latest} \
${ioTestPython}/bin/pytest -- -v test/io-tests "$@"
'';
@@ -141,7 +84,7 @@ let
''
export PATH="${postgrestProfiled}/bin:${curl}/bin:$PATH"
${withTmpDb postgresql} test/memory-tests.sh
${withTools.latest} test/memory-tests.sh
'';
dumpSchema =
@@ -155,7 +98,7 @@ let
env="$(cat ${postgrest.env})"
export PATH="$env/bin:$PATH"
${withTmpDb postgresql} \
${withTools.latest} \
${cabal-install}/bin/cabal v2-run ${devCabalOptions} --verbose=0 -- \
postgrest --dump-schema \
| ${yq}/bin/yq -y .
@@ -184,11 +127,11 @@ let
# collect all tests
HPCTIXFILE="$tmpdir"/io.tix \
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-exec ${devCabalOptions} \
${withTools.latest} ${cabal-install}/bin/cabal v2-exec ${devCabalOptions} \
${ioTestPython}/bin/pytest -- -v test/io-tests
HPCTIXFILE="$tmpdir"/spec.tix \
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
${withTools.latest} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
# collect all the tix files
${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix "$tmpdir"/io*.tix "$tmpdir"/spec.tix
@@ -251,8 +194,7 @@ buildEnv
dumpSchema.bin
coverage.bin
coverageDraftOverlay.bin
withAllVersions.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
-21
View File
@@ -1,21 +0,0 @@
# Wrap the `test/with_tmp_db` script with the required dependencies from Nix.
{ checkedShellScript }:
postgresql:
checkedShellScript
{
name = "postgrest-test-withtmpdb-${postgresql.name}";
docs = "Run the given command in a temporary database";
inRootDir = true;
redirectTixFiles = false;
}
''
# 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 "$@"
else
"$@"
fi
''
+80
View File
@@ -0,0 +1,80 @@
{ buildEnv
, checkedShellScript
, lib
, postgresqlVersions
}:
let
# Wrap the `test/with_tmp_db` script with the required dependencies from Nix.
withTmpDb =
{ name, postgresql }:
checkedShellScript
{
name = "postgrest-with-${name}";
docs = "Run the given command in a temporary database with ${name}";
inRootDir = true;
redirectTixFiles = false;
}
''
# 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 "$@"
else
"$@"
fi
'';
# Helper script for running a command against all PostgreSQL versions.
withAll =
let
runners =
builtins.map
(pg:
''
cat << EOF
Running against ${pg.name}...
EOF
trap 'echo "Failed on ${pg.name}"' exit
${withTmpDb pg} "$@"
trap "" exit
cat << EOF
Done running against ${pg.name}.
EOF
'')
postgresqlVersions;
in
checkedShellScript
{
name = "postgrest-with-all";
docs = "Run command against all supported PostgreSQL versions.";
inRootDir = true;
}
(lib.concatStringsSep "\n\n" runners);
# Create a `postgrest-with-postgresql-` for each PostgreSQL version
withVersions = builtins.map withTmpDb postgresqlVersions;
in
buildEnv
{
name =
"postgrest-with";
paths =
[
withAll.bin
] ++ (builtins.map (v: v.bin) withVersions);
}
# make withTools.latest available for other nix files
// {
latest = withTmpDb (builtins.head postgresqlVersions);
}
+4 -3
View File
@@ -27,11 +27,12 @@ lib.overrideDerivation postgrest.env (
pkgs.cabal-install
pkgs.cabal2nix
pkgs.postgresql
postgrest.nixpkgsUpgrade
postgrest.devtools
postgrest.tests
postgrest.style
postgrest.hsie.bin
postgrest.nixpkgsUpgrade
postgrest.style
postgrest.tests
postgrest.withTools
]
++ lib.optional memoryTests postgrest.tests.memoryTests
++ lib.optional docker postgrest.docker