2018-11-11 11:41:11 +03:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
|
|
|
|
|
|
|
with import ../lib/testing.nix { inherit system pkgs; };
|
2017-02-11 07:57:57 +03:00
|
|
|
with pkgs.lib;
|
2018-11-11 11:41:11 +03:00
|
|
|
|
2017-02-11 07:57:57 +03:00
|
|
|
let
|
|
|
|
postgresql-versions = pkgs.callPackages ../../pkgs/servers/sql/postgresql { };
|
|
|
|
test-sql = pkgs.writeText "postgresql-test" ''
|
|
|
|
CREATE EXTENSION pgcrypto; -- just to check if lib loading works
|
|
|
|
CREATE TABLE sth (
|
|
|
|
id int
|
|
|
|
);
|
|
|
|
INSERT INTO sth (id) VALUES (1);
|
|
|
|
INSERT INTO sth (id) VALUES (1);
|
|
|
|
INSERT INTO sth (id) VALUES (1);
|
|
|
|
INSERT INTO sth (id) VALUES (1);
|
|
|
|
INSERT INTO sth (id) VALUES (1);
|
2017-07-15 16:58:17 +03:00
|
|
|
CREATE TABLE xmltest ( doc xml );
|
|
|
|
INSERT INTO xmltest (doc) VALUES ('<test>ok</test>'); -- check if libxml2 enabled
|
2017-02-11 07:57:57 +03:00
|
|
|
'';
|
2017-07-15 16:54:42 +03:00
|
|
|
make-postgresql-test = postgresql-name: postgresql-package: makeTest {
|
2017-02-11 07:57:57 +03:00
|
|
|
name = postgresql-name;
|
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ zagy ];
|
|
|
|
};
|
2016-01-20 05:42:59 +03:00
|
|
|
|
2018-07-20 23:56:59 +03:00
|
|
|
machine = {...}:
|
2016-01-20 05:42:59 +03:00
|
|
|
{
|
2017-02-11 07:57:57 +03:00
|
|
|
services.postgresql.package=postgresql-package;
|
2016-01-20 05:42:59 +03:00
|
|
|
services.postgresql.enable = true;
|
2018-06-17 20:49:25 +03:00
|
|
|
|
|
|
|
services.postgresqlBackup.enable = true;
|
|
|
|
services.postgresqlBackup.databases = [ "postgres" ];
|
2016-01-20 05:42:59 +03:00
|
|
|
};
|
|
|
|
|
2017-02-11 07:57:57 +03:00
|
|
|
testScript = ''
|
2017-07-20 00:13:02 +03:00
|
|
|
sub check_count {
|
|
|
|
my ($select, $nlines) = @_;
|
|
|
|
return 'test $(sudo -u postgres psql postgres -tAc "' . $select . '"|wc -l) -eq ' . $nlines;
|
|
|
|
}
|
|
|
|
|
2017-02-11 07:57:57 +03:00
|
|
|
$machine->start;
|
|
|
|
$machine->waitForUnit("postgresql");
|
|
|
|
# postgresql should be available just after unit start
|
2017-07-20 00:13:02 +03:00
|
|
|
$machine->succeed("cat ${test-sql} | sudo -u postgres psql");
|
2017-02-11 07:57:57 +03:00
|
|
|
$machine->shutdown; # make sure that postgresql survive restart (bug #1735)
|
|
|
|
sleep(2);
|
|
|
|
$machine->start;
|
|
|
|
$machine->waitForUnit("postgresql");
|
2017-07-20 00:13:02 +03:00
|
|
|
$machine->fail(check_count("SELECT * FROM sth;", 3));
|
|
|
|
$machine->succeed(check_count("SELECT * FROM sth;", 5));
|
|
|
|
$machine->fail(check_count("SELECT * FROM sth;", 4));
|
|
|
|
$machine->succeed(check_count("SELECT xpath(\'/test/text()\', doc) FROM xmltest;", 1));
|
2018-06-17 20:49:25 +03:00
|
|
|
|
|
|
|
# Check backup service
|
|
|
|
$machine->succeed("systemctl start postgresqlBackup-postgres.service");
|
|
|
|
$machine->succeed("zcat /var/backup/postgresql/postgres.sql.gz | grep '<test>ok</test>'");
|
2018-11-06 23:59:29 +03:00
|
|
|
$machine->succeed("stat -c '%a' /var/backup/postgresql/postgres.sql.gz | grep 600");
|
2017-02-11 07:57:57 +03:00
|
|
|
$machine->shutdown;
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
in
|
|
|
|
mapAttrs' (p-name: p-package: {name=p-name; value=make-postgresql-test p-name p-package;}) postgresql-versions
|