lol

cargo-pgx/timescaledb_toolkit: add nixos test

authored by

Eric Wolf and committed by
Eric Wolf
9dc7a05a 4e189d76

+99
+1
nixos/tests/all-tests.nix
··· 683 683 terminal-emulators = handleTest ./terminal-emulators.nix {}; 684 684 tiddlywiki = handleTest ./tiddlywiki.nix {}; 685 685 tigervnc = handleTest ./tigervnc.nix {}; 686 + timescaledb = handleTest ./timescaledb.nix {}; 686 687 timezone = handleTest ./timezone.nix {}; 687 688 tinc = handleTest ./tinc {}; 688 689 tinydns = handleTest ./tinydns.nix {};
+93
nixos/tests/timescaledb.nix
··· 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 + 9 + with import ../lib/testing-python.nix { inherit system pkgs; }; 10 + with pkgs.lib; 11 + 12 + let 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; 87 + in 88 + mapAttrs' 89 + (name: package: { 90 + inherit name; 91 + value = make-postgresql-test name package; 92 + }) 93 + applicablePostgresqlVersions
+5
pkgs/servers/sql/postgresql/ext/timescaledb_toolkit.nix
··· 3 3 , buildPgxExtension 4 4 , postgresql 5 5 , stdenv 6 + , nixosTests 6 7 }: 7 8 8 9 buildPgxExtension rec { ··· 20 21 21 22 cargoSha256 = "sha256-ukjJ11LmfG+k8D20rj68i43gOWUN80nf3hIAjUWXihI="; 22 23 buildAndTestSubdir = "extension"; 24 + 25 + passthru.tests = { 26 + timescaledb_toolkit = nixosTests.timescaledb; 27 + }; 23 28 24 29 # tests take really long 25 30 doCheck = false;