nixpkgs/nixos/tests/postgresql/pgjwt.nix

55 lines
1.1 KiB
Nix
Raw Normal View History

{
pkgs,
makeTest,
postgresql: refactor `postgresqlVersions` attribute & tests Every postgresql testcase essentially does the following things: * Filter `postgresqlVersions` for server packages * Filter postgresql server packages for suitable ones (i.e. extensions must support the given version) * Generate an attribute-set of testcases The first item became necessary in 7ab1e888334ddc2745b285e3df0b0efd5839d0f8 given that `postgresql/default.nix` now exposes JIT and non-JIT servers AND a `libpq` that is not suitable for the tests here. This changes restructures this a little bit, i.e.: * Having an attribute-set that contains a bunch of postgresql servers and a single client package seems odd (and the sole consumer of `postgresqlVersions` in nixpkgs, the test suite, has to take that into account). Hence, postgresql's default.nix now provides `libpq` (the client) and a `postgresqlVersions` attribute with all supported JIT and non-JIT variants of postgresql. * Each test-case gets a third argument, a function called `genTests`: this function sets `recurseForDerivations = true;` and generates an attribute-set of tests for each postgresql version given a function that returns a testcase or multiple test-cases (`makeTestFor`). The argument to `makeTestFor` is a postgresql server package. This function also accepts a filter predicate that is passed against `filterAttrs` to remove postgresql server packages that are not suitable for the test (e.g. because the version isn't supported by the extension to test). I checked by making sure that the `.drv` doesn't change on staging with this change on top for postgresq, postgresql-jit, postgresql-wal-receiver, postgresql-tls-client-cert, anonymizer, pgjwt, pgvecto-rs, timescaledb, tsja and wal2json.
2025-01-26 13:10:53 +01:00
genTests,
}:
2019-11-06 16:45:57 +01:00
let
inherit (pkgs) lib;
makeTestFor =
package:
makeTest {
name = "pgjwt-${package.name}";
meta = with lib.maintainers; {
maintainers = [
spinus
willibutz
];
2017-02-26 10:14:32 +00:00
};
nodes.master =
{ ... }:
{
services.postgresql = {
inherit package;
enable = true;
extensions =
ps: with ps; [
pgjwt
pgtap
];
};
};
testScript =
{ nodes, ... }:
let
sqlSU = "${nodes.master.services.postgresql.superUser}";
pgProve = "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}";
inherit (nodes.master.services.postgresql.package.pkgs) pgjwt;
in
''
start_all()
master.wait_for_unit("postgresql")
master.succeed(
"${pkgs.sudo}/bin/sudo -u ${sqlSU} ${pgProve}/bin/pg_prove -d postgres -v -f ${pgjwt.src}/test.sql"
)
'';
};
in
postgresql: refactor `postgresqlVersions` attribute & tests Every postgresql testcase essentially does the following things: * Filter `postgresqlVersions` for server packages * Filter postgresql server packages for suitable ones (i.e. extensions must support the given version) * Generate an attribute-set of testcases The first item became necessary in 7ab1e888334ddc2745b285e3df0b0efd5839d0f8 given that `postgresql/default.nix` now exposes JIT and non-JIT servers AND a `libpq` that is not suitable for the tests here. This changes restructures this a little bit, i.e.: * Having an attribute-set that contains a bunch of postgresql servers and a single client package seems odd (and the sole consumer of `postgresqlVersions` in nixpkgs, the test suite, has to take that into account). Hence, postgresql's default.nix now provides `libpq` (the client) and a `postgresqlVersions` attribute with all supported JIT and non-JIT variants of postgresql. * Each test-case gets a third argument, a function called `genTests`: this function sets `recurseForDerivations = true;` and generates an attribute-set of tests for each postgresql version given a function that returns a testcase or multiple test-cases (`makeTestFor`). The argument to `makeTestFor` is a postgresql server package. This function also accepts a filter predicate that is passed against `filterAttrs` to remove postgresql server packages that are not suitable for the test (e.g. because the version isn't supported by the extension to test). I checked by making sure that the `.drv` doesn't change on staging with this change on top for postgresq, postgresql-jit, postgresql-wal-receiver, postgresql-tls-client-cert, anonymizer, pgjwt, pgvecto-rs, timescaledb, tsja and wal2json.
2025-01-26 13:10:53 +01:00
genTests {
inherit makeTestFor;
filter = _: p: !p.pkgs.pgjwt.meta.broken;
}