Skip to content

Commit

Permalink
postgresqlPackages.pgvecto-rs: make passthru.tests work with correct …
Browse files Browse the repository at this point in the history
…package

Same reasoning as commit before.
  • Loading branch information
wolfgangwalther committed Nov 1, 2024
1 parent 9d8b393 commit 7a48f9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
31 changes: 15 additions & 16 deletions nixos/tests/pgvecto-rs.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# mostly copied from ./timescaledb.nix which was copied from ./postgresql.nix
# as it seemed unapproriate to test additional extensions for postgresql there.

{ system ? builtins.currentSystem
, config ? { }
, pkgs ? import ../.. { inherit system config; }
Expand All @@ -10,7 +7,6 @@ with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

let
postgresql-versions = import ../../pkgs/servers/sql/postgresql pkgs;
# Test cases from https://docs.pgvecto.rs/use-cases/hybrid-search.html
test-sql = pkgs.writeText "postgresql-test" ''
CREATE EXTENSION vectors;
Expand All @@ -27,8 +23,9 @@ let
('a thin cat sat on a mat and ate a thin rat', '[7, 8, 9]'),
('a thin dog sat on a mat and ate a thin rat', '[10, 11, 12]');
'';
make-postgresql-test = postgresql-name: postgresql-package: makeTest {
name = postgresql-name;

makePgVectorsTest = postgresqlPackage: makeTest {
name = "pgvecto-rs-${postgresqlPackage.name}";
meta = with pkgs.lib.maintainers; {
maintainers = [ diogotcorreia ];
};
Expand All @@ -37,15 +34,19 @@ let
{
services.postgresql = {
enable = true;
package = postgresql-package;
package = postgresqlPackage;
extraPlugins = ps: with ps; [
pgvecto-rs
];
settings.shared_preload_libraries = "vectors";
};
};

testScript = ''
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
Expand All @@ -56,7 +57,7 @@ let
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 = '${postgresql-package.pkgs.pgvecto-rs.version}';", 1))
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}")
Expand All @@ -66,11 +67,9 @@ let
'';

};
applicablePostgresqlVersions = filterAttrs (_: value: versionAtLeast value.version "14") postgresql-versions;
in
mapAttrs'
(name: package: {
inherit name;
value = make-postgresql-test name package;
})
applicablePostgresqlVersions
{
default = makePgVectorsTest pkgs.postgresql;
jit = makePgVectorsTest pkgs.postgresql_jit;
passthru.override = p: makePgVectorsTest p;
}
4 changes: 1 addition & 3 deletions pkgs/servers/sql/postgresql/ext/pgvecto-rs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ in

passthru = {
updateScript = nix-update-script { };
tests = {
pgvecto-rs = nixosTests.pgvecto-rs;
};
tests = nixosTests.pgvecto-rs.passthru.override postgresql;
};

meta = with lib; {
Expand Down

0 comments on commit 7a48f9e

Please sign in to comment.