nix(refactor): Move withPostgresqlVersions and withAllVersions to new withTools
This commit is contained in:
committed by
Wolfgang Walther
parent
dccce946e3
commit
32bac81d91
@@ -172,7 +172,7 @@ jobs:
|
|||||||
cachix use postgrest
|
cachix use postgrest
|
||||||
- run:
|
- run:
|
||||||
name: Install testing scripts
|
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:
|
- run:
|
||||||
name: Run coverage (io tests and spec tests against PostgreSQL 13)
|
name: Run coverage (io tests and spec tests against PostgreSQL 13)
|
||||||
command: postgrest-coverage
|
command: postgrest-coverage
|
||||||
|
|||||||
+3
-3
@@ -112,13 +112,13 @@ rec {
|
|||||||
nixpkgsUpgrade =
|
nixpkgsUpgrade =
|
||||||
pkgs.callPackage nix/nixpkgs-upgrade.nix { };
|
pkgs.callPackage nix/nixpkgs-upgrade.nix { };
|
||||||
|
|
||||||
withTmpDb =
|
withTools =
|
||||||
pkgs.callPackage nix/withtmpdb.nix { };
|
pkgs.callPackage nix/withtools.nix { inherit postgresqlVersions; };
|
||||||
|
|
||||||
# Scripts for running tests.
|
# Scripts for running tests.
|
||||||
tests =
|
tests =
|
||||||
pkgs.callPackage nix/tests.nix {
|
pkgs.callPackage nix/tests.nix {
|
||||||
inherit postgrest postgrestProfiled postgresqlVersions devCabalOptions withTmpDb;
|
inherit postgrest postgrestProfiled devCabalOptions withTools;
|
||||||
ghc = pkgs.haskell.compiler."${compiler}";
|
ghc = pkgs.haskell.compiler."${compiler}";
|
||||||
hpc-codecov = pkgs.haskell.packages."${compiler}".hpc-codecov;
|
hpc-codecov = pkgs.haskell.packages."${compiler}".hpc-codecov;
|
||||||
};
|
};
|
||||||
|
|||||||
+9
-67
@@ -10,71 +10,14 @@
|
|||||||
, gnugrep
|
, gnugrep
|
||||||
, haskell
|
, haskell
|
||||||
, hpc-codecov
|
, hpc-codecov
|
||||||
, lib
|
|
||||||
, postgresql
|
|
||||||
, postgresqlVersions
|
|
||||||
, postgrest
|
, postgrest
|
||||||
, postgrestProfiled
|
, postgrestProfiled
|
||||||
, python3
|
, python3
|
||||||
, runtimeShell
|
, runtimeShell
|
||||||
, withTmpDb
|
, withTools
|
||||||
, yq
|
, yq
|
||||||
}:
|
}:
|
||||||
let
|
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 =
|
testSpec =
|
||||||
checkedShellScript
|
checkedShellScript
|
||||||
{
|
{
|
||||||
@@ -86,7 +29,7 @@ let
|
|||||||
env="$(cat ${postgrest.env})"
|
env="$(cat ${postgrest.env})"
|
||||||
export PATH="$env/bin:$PATH"
|
export PATH="$env/bin:$PATH"
|
||||||
|
|
||||||
${withTmpDb postgresql} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
|
${withTools.latest} ${cabal-install}/bin/cabal v2-test ${devCabalOptions}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
testSpecIdempotence =
|
testSpecIdempotence =
|
||||||
@@ -100,7 +43,7 @@ let
|
|||||||
env="$(cat ${postgrest.env})"
|
env="$(cat ${postgrest.env})"
|
||||||
export PATH="$env/bin:$PATH"
|
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} && \
|
||||||
${cabal-install}/bin/cabal v2-test ${devCabalOptions}"
|
${cabal-install}/bin/cabal v2-test ${devCabalOptions}"
|
||||||
'';
|
'';
|
||||||
@@ -127,7 +70,7 @@ let
|
|||||||
export PATH="$env/bin:$PATH"
|
export PATH="$env/bin:$PATH"
|
||||||
|
|
||||||
${cabal-install}/bin/cabal v2-build ${devCabalOptions}
|
${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 "$@"
|
${ioTestPython}/bin/pytest -- -v test/io-tests "$@"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@@ -141,7 +84,7 @@ let
|
|||||||
''
|
''
|
||||||
export PATH="${postgrestProfiled}/bin:${curl}/bin:$PATH"
|
export PATH="${postgrestProfiled}/bin:${curl}/bin:$PATH"
|
||||||
|
|
||||||
${withTmpDb postgresql} test/memory-tests.sh
|
${withTools.latest} test/memory-tests.sh
|
||||||
'';
|
'';
|
||||||
|
|
||||||
dumpSchema =
|
dumpSchema =
|
||||||
@@ -155,7 +98,7 @@ let
|
|||||||
env="$(cat ${postgrest.env})"
|
env="$(cat ${postgrest.env})"
|
||||||
export PATH="$env/bin:$PATH"
|
export PATH="$env/bin:$PATH"
|
||||||
|
|
||||||
${withTmpDb postgresql} \
|
${withTools.latest} \
|
||||||
${cabal-install}/bin/cabal v2-run ${devCabalOptions} --verbose=0 -- \
|
${cabal-install}/bin/cabal v2-run ${devCabalOptions} --verbose=0 -- \
|
||||||
postgrest --dump-schema \
|
postgrest --dump-schema \
|
||||||
| ${yq}/bin/yq -y .
|
| ${yq}/bin/yq -y .
|
||||||
@@ -184,11 +127,11 @@ let
|
|||||||
|
|
||||||
# collect all tests
|
# collect all tests
|
||||||
HPCTIXFILE="$tmpdir"/io.tix \
|
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
|
${ioTestPython}/bin/pytest -- -v test/io-tests
|
||||||
|
|
||||||
HPCTIXFILE="$tmpdir"/spec.tix \
|
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
|
# collect all the tix files
|
||||||
${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix "$tmpdir"/io*.tix "$tmpdir"/spec.tix
|
${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
|
dumpSchema.bin
|
||||||
coverage.bin
|
coverage.bin
|
||||||
coverageDraftOverlay.bin
|
coverageDraftOverlay.bin
|
||||||
withAllVersions.bin
|
];
|
||||||
] ++ withPostgresqlVersions;
|
|
||||||
}
|
}
|
||||||
# The memory tests have large dependencies (a profiled build of PostgREST)
|
# 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
|
# and are run less often than the spec tests, so we don't include them in
|
||||||
|
|||||||
@@ -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
|
|
||||||
''
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -27,11 +27,12 @@ lib.overrideDerivation postgrest.env (
|
|||||||
pkgs.cabal-install
|
pkgs.cabal-install
|
||||||
pkgs.cabal2nix
|
pkgs.cabal2nix
|
||||||
pkgs.postgresql
|
pkgs.postgresql
|
||||||
postgrest.nixpkgsUpgrade
|
|
||||||
postgrest.devtools
|
postgrest.devtools
|
||||||
postgrest.tests
|
|
||||||
postgrest.style
|
|
||||||
postgrest.hsie.bin
|
postgrest.hsie.bin
|
||||||
|
postgrest.nixpkgsUpgrade
|
||||||
|
postgrest.style
|
||||||
|
postgrest.tests
|
||||||
|
postgrest.withTools
|
||||||
]
|
]
|
||||||
++ lib.optional memoryTests postgrest.tests.memoryTests
|
++ lib.optional memoryTests postgrest.tests.memoryTests
|
||||||
++ lib.optional docker postgrest.docker
|
++ lib.optional docker postgrest.docker
|
||||||
|
|||||||
Reference in New Issue
Block a user