Skip to content

Commit

Permalink
nixosTests.postgresql: run nixfmt
Browse files Browse the repository at this point in the history
Because with as many changes as in here anybody working on those test
files will have merge conflicts anyway.
  • Loading branch information
wolfgangwalther committed Nov 8, 2024
1 parent 066ab04 commit 6ec6813
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 360 deletions.
30 changes: 18 additions & 12 deletions nixos/tests/postgresql/anonymizer.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
{ pkgs
, makeTest
{
pkgs,
makeTest,
}:

let
inherit (pkgs) lib;

makeTestFor = package:
makeTestFor =
package:
makeTest {
name = "postgresql_anonymizer-${package.name}";
meta.maintainers = lib.teams.flyingcircus.members;

nodes.machine = { pkgs, ... }: {
environment.systemPackages = [ pkgs.pg-dump-anon ];
services.postgresql = {
inherit package;
enable = true;
extraPlugins = ps: [ ps.anonymizer ];
settings.shared_preload_libraries = [ "anon" ];
nodes.machine =
{ pkgs, ... }:
{
environment.systemPackages = [ pkgs.pg-dump-anon ];
services.postgresql = {
inherit package;
enable = true;
extraPlugins = ps: [ ps.anonymizer ];
settings.shared_preload_libraries = [ "anon" ];
};
};
};

testScript = ''
start_all()
Expand Down Expand Up @@ -103,7 +107,9 @@ let
};
in
lib.recurseIntoAttrs (
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (lib.filterAttrs (_: p: !p.pkgs.anonymizer.meta.broken) pkgs.postgresqlVersions)
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (
lib.filterAttrs (_: p: !p.pkgs.anonymizer.meta.broken) pkgs.postgresqlVersions
)
// {
passthru.override = p: makeTestFor p;
}
Expand Down
53 changes: 33 additions & 20 deletions nixos/tests/postgresql/pgjwt.nix
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
{ pkgs
, makeTest
{
pkgs,
makeTest,
}:

let
inherit (pkgs) lib;

makeTestFor = package:
makeTestFor =
package:
makeTest {
name = "pgjwt-${package.name}";
meta = with lib.maintainers; {
maintainers = [ spinus willibutz ];
maintainers = [
spinus
willibutz
];
};

nodes.master = { ... }:
nodes.master =
{ ... }:
{
services.postgresql = {
inherit package;
enable = true;
extraPlugins = ps: with ps; [ pgjwt pgtap ];
extraPlugins =
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"
)
'';
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
lib.recurseIntoAttrs (
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (lib.filterAttrs (_: p: !p.pkgs.pgjwt.meta.broken) pkgs.postgresqlVersions)
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (
lib.filterAttrs (_: p: !p.pkgs.pgjwt.meta.broken) pkgs.postgresqlVersions
)
// {
passthru.override = p: makeTestFor p;
}
Expand Down
57 changes: 32 additions & 25 deletions nixos/tests/postgresql/pgvecto-rs.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ pkgs
, makeTest
{
pkgs,
makeTest,
}:

let
Expand All @@ -22,52 +23,58 @@ let
('a thin dog sat on a mat and ate a thin rat', '[10, 11, 12]');
'';

makeTestFor = postgresqlPackage:
makeTestFor =
postgresqlPackage:
makeTest {
name = "pgvecto-rs-${postgresqlPackage.name}";
meta = with lib.maintainers; {
maintainers = [ diogotcorreia ];
};

nodes.machine = { ... }:
nodes.machine =
{ ... }:
{
services.postgresql = {
enable = true;
package = postgresqlPackage;
extraPlugins = ps: with ps; [
pgvecto-rs
];
extraPlugins =
ps: with ps; [
pgvecto-rs
];
settings.shared_preload_libraries = "vectors";
};
};

testScript = { nodes, ... }:
let
inherit (nodes.machine.services.postgresql.package.pkgs) pgvecto-rs;
in
''
def check_count(statement, lines):
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
statement, lines
)
testScript =
{ nodes, ... }:
let
inherit (nodes.machine.services.postgresql.package.pkgs) pgvecto-rs;
in
''
def check_count(statement, lines):
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
statement, lines
)
machine.start()
machine.wait_for_unit("postgresql")
machine.start()
machine.wait_for_unit("postgresql")
with subtest("Postgresql with extension vectors is available just after unit start"):
machine.succeed(check_count("SELECT * FROM pg_available_extensions WHERE name = 'vectors' AND default_version = '${pgvecto-rs.version}';", 1))
with subtest("Postgresql with extension vectors is available just after unit start"):
machine.succeed(check_count("SELECT * FROM pg_available_extensions WHERE name = 'vectors' AND default_version = '${pgvecto-rs.version}';", 1))
machine.succeed("sudo -u postgres psql -f ${test-sql}")
machine.succeed("sudo -u postgres psql -f ${test-sql}")
machine.succeed(check_count("SELECT content, embedding FROM items WHERE to_tsvector('english', content) @@ 'cat & rat'::tsquery;", 2))
machine.succeed(check_count("SELECT content, embedding FROM items WHERE to_tsvector('english', content) @@ 'cat & rat'::tsquery;", 2))
machine.shutdown()
'';
machine.shutdown()
'';
};
in
lib.recurseIntoAttrs (
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (lib.filterAttrs (_: p: !p.pkgs.pgvecto-rs.meta.broken) pkgs.postgresqlVersions)
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (
lib.filterAttrs (_: p: !p.pkgs.pgvecto-rs.meta.broken) pkgs.postgresqlVersions
)
// {
passthru.override = p: makeTestFor p;
}
Expand Down
34 changes: 20 additions & 14 deletions nixos/tests/postgresql/postgresql-jit.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{ pkgs
, makeTest
{
pkgs,
makeTest,
}:

let
inherit (pkgs) lib;

makeTestFor = package:
makeTestFor =
package:
makeTest {
name = "postgresql-jit-${package.name}";
meta.maintainers = with lib.maintainers; [ ma27 ];

nodes.machine = { pkgs, ... }: {
services.postgresql = {
inherit package;
enable = true;
enableJIT = true;
initialScript = pkgs.writeText "init.sql" ''
create table demo (id int);
insert into demo (id) select generate_series(1, 5);
'';
nodes.machine =
{ pkgs, ... }:
{
services.postgresql = {
inherit package;
enable = true;
enableJIT = true;
initialScript = pkgs.writeText "init.sql" ''
create table demo (id int);
insert into demo (id) select generate_series(1, 5);
'';
};
};
};

testScript = ''
machine.start()
Expand All @@ -45,7 +49,9 @@ let
};
in
lib.recurseIntoAttrs (
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (lib.filterAttrs (n: _: lib.hasSuffix "_jit" n) pkgs.postgresqlVersions)
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) (
lib.filterAttrs (n: _: lib.hasSuffix "_jit" n) pkgs.postgresqlVersions
)
// {
passthru.override = p: makeTestFor p;
}
Expand Down
Loading

0 comments on commit 6ec6813

Please sign in to comment.