at 23.11-pre 2.7 kB view raw
1# mostly copied from ./postgresql.nix as it seemed unapproriate to 2# test additional extensions for postgresql there. 3 4{ system ? builtins.currentSystem 5, config ? { } 6, pkgs ? import ../.. { inherit system config; } 7}: 8 9with import ../lib/testing-python.nix { inherit system pkgs; }; 10with pkgs.lib; 11 12let 13 postgresql-versions = import ../../pkgs/servers/sql/postgresql pkgs; 14 test-sql = pkgs.writeText "postgresql-test" '' 15 CREATE EXTENSION timescaledb; 16 CREATE EXTENSION timescaledb_toolkit; 17 18 CREATE TABLE sth ( 19 time TIMESTAMPTZ NOT NULL, 20 value DOUBLE PRECISION 21 ); 22 23 SELECT create_hypertable('sth', 'time'); 24 25 INSERT INTO sth (time, value) VALUES 26 ('2003-04-12 04:05:06 America/New_York', 1.0), 27 ('2003-04-12 04:05:07 America/New_York', 2.0), 28 ('2003-04-12 04:05:08 America/New_York', 3.0), 29 ('2003-04-12 04:05:09 America/New_York', 4.0), 30 ('2003-04-12 04:05:10 America/New_York', 5.0) 31 ; 32 33 WITH t AS ( 34 SELECT 35 time_bucket('1 day'::interval, time) AS dt, 36 stats_agg(value) AS stats 37 FROM sth 38 GROUP BY time_bucket('1 day'::interval, time) 39 ) 40 SELECT 41 average(stats) 42 FROM t; 43 ''; 44 make-postgresql-test = postgresql-name: postgresql-package: makeTest { 45 name = postgresql-name; 46 meta = with pkgs.lib.maintainers; { 47 maintainers = [ typetetris ]; 48 }; 49 50 nodes.machine = { ... }: 51 { 52 services.postgresql = { 53 enable = true; 54 package = postgresql-package; 55 extraPlugins = with postgresql-package.pkgs; [ 56 timescaledb 57 timescaledb_toolkit 58 ]; 59 settings = { shared_preload_libraries = "timescaledb, timescaledb_toolkit"; }; 60 }; 61 }; 62 63 testScript = '' 64 def check_count(statement, lines): 65 return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format( 66 statement, lines 67 ) 68 69 70 machine.start() 71 machine.wait_for_unit("postgresql") 72 73 with subtest("Postgresql with extensions timescaledb and timescaledb_toolkit is available just after unit start"): 74 machine.succeed( 75 "sudo -u postgres psql -f ${test-sql}" 76 ) 77 78 machine.fail(check_count("SELECT * FROM sth;", 3)) 79 machine.succeed(check_count("SELECT * FROM sth;", 5)) 80 machine.fail(check_count("SELECT * FROM sth;", 4)) 81 82 machine.shutdown() 83 ''; 84 85 }; 86 applicablePostgresqlVersions = filterAttrs (_: value: versionAtLeast value.version "12") postgresql-versions; 87in 88mapAttrs' 89 (name: package: { 90 inherit name; 91 value = make-postgresql-test name package; 92 }) 93 applicablePostgresqlVersions