postgresqlPackages: refactor extension checks

The withPackages scope now provides a "postgresqlTestExtension" helper
which removes all the boilerplate for those kind of tests.

This was Mario Rodas' idea in #299756.
This commit is contained in:
Wolfgang Walther 2024-09-20 21:26:18 +02:00
parent b6567e0a54
commit 2b9fa464cf
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1
7 changed files with 45 additions and 96 deletions

View File

@ -4,7 +4,7 @@
, fetchFromGitHub
, h3_4
, postgresql
, postgresqlTestHook
, postgresqlTestExtension
}:
stdenv.mkDerivation (finalAttrs: {
@ -42,14 +42,9 @@ stdenv.mkDerivation (finalAttrs: {
install -D -t $out/share/postgresql/extension h3_postgis/h3_postgis-*.sql h3_postgis/h3_postgis.control
'';
passthru.tests.extension = stdenv.mkDerivation {
name = "h3-pg-test";
dontUnpack = true;
doCheck = true;
buildInputs = [ postgresqlTestHook ];
nativeCheckInputs = [ (postgresql.withPackages (ps: [ ps.h3-pg ps.postgis ])) ];
postgresqlTestUserOptions = "LOGIN SUPERUSER";
passAsFile = [ "sql" ];
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
withPackages = [ "postgis" ];
sql = ''
CREATE EXTENSION h3;
CREATE EXTENSION h3_postgis CASCADE;
@ -57,13 +52,6 @@ stdenv.mkDerivation (finalAttrs: {
SELECT h3_lat_lng_to_cell(POINT('37.3615593,-122.0553238'), 5);
SELECT ST_NPoints(h3_cell_to_boundary_geometry('8a63a9a99047fff'));
'';
failureHook = "postgresqlStop";
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f $sqlPath
runHook postCheck
'';
installPhase = "touch $out";
};
meta = with lib; {

View File

@ -3,7 +3,7 @@
, cmake
, fetchFromGitHub
, postgresql
, postgresqlTestHook
, postgresqlTestExtension
}:
stdenv.mkDerivation (finalAttrs: {
@ -40,14 +40,8 @@ stdenv.mkDerivation (finalAttrs: {
"-DBUILD_FOR_DISTRIBUTING=ON"
];
passthru.tests.extension = stdenv.mkDerivation {
name = "lantern-pg-test";
dontUnpack = true;
doCheck = true;
buildInputs = [ postgresqlTestHook ];
nativeCheckInputs = [ (postgresql.withPackages (_: [ finalAttrs.finalPackage ])) ];
postgresqlTestUserOptions = "LOGIN SUPERUSER";
passAsFile = [ "sql" ];
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION lantern;
@ -57,13 +51,6 @@ stdenv.mkDerivation (finalAttrs: {
CREATE INDEX ON small_world USING lantern_hnsw (vector dist_l2sq_ops)
WITH (M=2, ef_construction=10, ef=4, dim=3);
'';
failureHook = "postgresqlStop";
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f $sqlPath
runHook postCheck
'';
installPhase = "touch $out";
};
meta = with lib; {

View File

@ -2,7 +2,7 @@
, stdenv
, fetchFromGitHub
, postgresql
, postgresqlTestHook
, postgresqlTestExtension
, testers
, zlib
}:
@ -30,20 +30,9 @@ stdenv.mkDerivation (finalAttrs: {
version = testers.testVersion {
package = finalAttrs.finalPackage;
};
extension = stdenv.mkDerivation {
name = "plpgsql-check-test";
dontUnpack = true;
doCheck = true;
buildInputs = [ postgresqlTestHook ];
nativeCheckInputs = [ (postgresql.withPackages (ps: [ ps.pg_repack ])) ];
postgresqlTestUserOptions = "LOGIN SUPERUSER";
failureHook = "postgresqlStop";
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -c "CREATE EXTENSION pg_repack;"
runHook postCheck
'';
installPhase = "touch $out";
extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = "CREATE EXTENSION pg_repack;";
};
};

View File

@ -1,4 +1,4 @@
{ lib, stdenv, fetchFromGitHub, postgresql, postgresqlTestHook }:
{ lib, stdenv, fetchFromGitHub, postgresql, postgresqlTestExtension }:
stdenv.mkDerivation (finalAttrs: {
pname = "pg_squeeze";
@ -25,18 +25,12 @@ stdenv.mkDerivation (finalAttrs: {
runHook postInstall
'';
passthru.tests.extension = stdenv.mkDerivation {
name = "pg_squeeze-test";
dontUnpack = true;
doCheck = true;
nativeCheckInputs = [ postgresqlTestHook (postgresql.withPackages (_: [ finalAttrs.finalPackage ])) ];
failureHook = "postgresqlStop";
postgresqlTestUserOptions = "LOGIN SUPERUSER";
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
postgresqlExtraSettings = ''
wal_level = logical
shared_preload_libraries = 'pg_squeeze'
'';
passAsFile = [ "sql" ];
sql = ''
CREATE EXTENSION pg_squeeze;
@ -48,12 +42,6 @@ stdenv.mkDerivation (finalAttrs: {
VALUES ('public', 'a', ('{30}', '{22}', NULL, NULL, '{3, 5}'));
SELECT squeeze.squeeze_table('public', 'a', NULL, NULL, NULL);
'';
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f $sqlPath
runHook postCheck
'';
installPhase = "touch $out";
};
meta = with lib; {

View File

@ -3,7 +3,7 @@
, fetchFromGitHub
, libsodium
, postgresql
, postgresqlTestHook
, postgresqlTestExtension
}:
stdenv.mkDerivation (finalAttrs: {
@ -35,17 +35,11 @@ stdenv.mkDerivation (finalAttrs: {
runHook postInstall
'';
passthru.tests.extension = stdenv.mkDerivation {
name = "pgsodium-test";
dontUnpack = true;
doCheck = true;
nativeCheckInputs = [ postgresqlTestHook (postgresql.withPackages (_: [ finalAttrs.finalPackage ])) ];
failureHook = "postgresqlStop";
postgresqlTestUserOptions = "LOGIN SUPERUSER";
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
postgresqlExtraSettings = ''
shared_preload_libraries=pgsodium
'';
passAsFile = [ "sql" ];
sql = ''
CREATE EXTENSION pgsodium;
@ -54,12 +48,6 @@ stdenv.mkDerivation (finalAttrs: {
SELECT pgsodium.randombytes_random() FROM generate_series(0, 5);
SELECT * FROM pgsodium.crypto_box_new_keypair();
'';
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f $sqlPath
runHook postCheck
'';
installPhase = "touch $out";
};
meta = with lib; {

View File

@ -1,13 +1,13 @@
{ lib, stdenv, fetchFromGitHub, postgresql, postgresqlTestHook }:
{ lib, stdenv, fetchFromGitHub, postgresql, postgresqlTestExtension }:
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
pname = "plpgsql-check";
version = "2.7.5";
src = fetchFromGitHub {
owner = "okbob";
repo = "plpgsql_check";
rev = "v${version}";
rev = "v${finalAttrs.version}";
hash = "sha256-CD/G/wX6o+mC6gowlpFe1DdJWyh3cB9wxSsW2GXrENE=";
};
@ -19,28 +19,17 @@ stdenv.mkDerivation rec {
install -D -t $out/share/postgresql/extension *.control
'';
passthru.tests.extension = stdenv.mkDerivation {
name = "plpgsql-check-test";
dontUnpack = true;
doCheck = true;
buildInputs = [ postgresqlTestHook ];
nativeCheckInputs = [ (postgresql.withPackages (ps: [ ps.plpgsql_check ])) ];
postgresqlTestUserOptions = "LOGIN SUPERUSER";
failureHook = "postgresqlStop";
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -c "CREATE EXTENSION plpgsql_check;"
runHook postCheck
'';
installPhase = "touch $out";
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = "CREATE EXTENSION plpgsql_check;";
};
meta = with lib; {
description = "Linter tool for language PL/pgSQL";
homepage = "https://github.com/okbob/plpgsql_check";
changelog = "https://github.com/okbob/plpgsql_check/releases/tag/v${version}";
changelog = "https://github.com/okbob/plpgsql_check/releases/tag/v${finalAttrs.version}";
platforms = postgresql.meta.platforms;
license = licenses.mit;
maintainers = [ ];
};
}
})

View File

@ -16,6 +16,7 @@ let
# for postgresql.pkgs
, self, newScope, buildEnv
, stdenvNoCC, postgresqlTestHook
# source specification
, version, hash, muslPatches ? {}
@ -271,6 +272,25 @@ let
inherit (llvmPackages) llvm;
postgresql = this;
stdenv = stdenv';
postgresqlTestExtension = { finalPackage, withPackages ? [], ... } @ extraArgs:
stdenvNoCC.mkDerivation ({
name = "${finalPackage.name}-test-extension";
dontUnpack = true;
doCheck = true;
nativeCheckInputs = [
postgresqlTestHook
(this.withPackages (ps: [ finalPackage ] ++ (map (p: ps."${p}") withPackages)))
];
failureHook = "postgresqlStop";
postgresqlTestUserOptions = "LOGIN SUPERUSER";
passAsFile = [ "sql" ];
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f "$sqlPath"
runHook postCheck
'';
installPhase = "touch $out";
} // extraArgs);
};
newSelf = self // scope;
newSuper = { callPackage = newScope (scope // this.pkgs); };