nixosTests.postgresql-wal-receiver: avoid manual imports

Manually importing postgresql packages from the /pkgs/ folder or
manually importing the test from /nixos/tests/ in generic.nix is not
only ugly, but also forbidden should we ever move to pkgs/by-name.

We can achieve almost the same with a slightly different setup. We allow
overriding the postgresql package for the test via passthru.override, to
make sure that each postgresql_xx.tests.postgresql-wal-receiver is
properly teted with the right version.
This commit is contained in:
Wolfgang Walther 2024-11-01 19:21:50 +01:00
parent 75d51c5889
commit a1ae4377e0
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1
2 changed files with 6 additions and 21 deletions

View File

@ -1,7 +1,6 @@
{ system ? builtins.currentSystem,
config ? {},
pkgs ? import ../.. { inherit system config; },
package ? null
}:
with import ../lib/testing-python.nix { inherit system pkgs; };
@ -9,13 +8,6 @@ with import ../lib/testing-python.nix { inherit system pkgs; };
let
lib = pkgs.lib;
# Makes a test for a PostgreSQL package, given by name and looked up from `pkgs`.
makeTestAttribute = name:
{
inherit name;
value = makePostgresqlWalReceiverTest pkgs."${name}";
};
makePostgresqlWalReceiverTest = pkg:
let
postgresqlDataDir = "/var/lib/postgresql/${pkg.psqlSchema}";
@ -114,11 +106,8 @@ let
)
'';
};
in
if package == null then
# all-tests.nix: Maps the generic function over all attributes of PostgreSQL packages
builtins.listToAttrs (map makeTestAttribute (builtins.attrNames (import ../../pkgs/servers/sql/postgresql pkgs)))
else
# Called directly from <package>.tests
makePostgresqlWalReceiverTest package
lib.concatMapAttrs (n: p: { ${n} = makePostgresqlWalReceiverTest p; }) pkgs.postgresqlVersions
// {
passthru.override = p: makePostgresqlWalReceiverTest p;
}

View File

@ -20,7 +20,7 @@ let
, version, hash, muslPatches ? {}
# for tests
, testers
, testers, nixosTests
# JIT
, jitSupport
@ -312,11 +312,7 @@ let
};
tests = {
postgresql-wal-receiver = import ../../../../nixos/tests/postgresql-wal-receiver.nix {
inherit (stdenv) system;
pkgs = self;
package = this;
};
postgresql-wal-receiver = nixosTests.postgresql-wal-receiver.passthru.override finalAttrs.finalPackage;
pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
} // lib.optionalAttrs jitSupport {
postgresql-jit = import ../../../../nixos/tests/postgresql-jit.nix {