2017-02-11 05:57:57 +01:00
|
|
|
{ system ? builtins.currentSystem }:
|
|
|
|
with import ../lib/testing.nix { inherit system; };
|
|
|
|
with pkgs.lib;
|
|
|
|
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 15:58:17 +02:00
|
|
|
CREATE TABLE xmltest ( doc xml );
|
|
|
|
INSERT INTO xmltest (doc) VALUES ('<test>ok</test>'); -- check if libxml2 enabled
|
2017-02-11 05:57:57 +01:00
|
|
|
'';
|
2017-07-15 15:54:42 +02:00
|
|
|
make-postgresql-test = postgresql-name: postgresql-package: makeTest {
|
2017-02-11 05:57:57 +01:00
|
|
|
name = postgresql-name;
|
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ zagy ];
|
|
|
|
};
|
2016-01-20 03:42:59 +01:00
|
|
|
|
2017-02-11 05:57:57 +01:00
|
|
|
machine = {pkgs, config, ...}:
|
2016-01-20 03:42:59 +01:00
|
|
|
{
|
2017-02-11 05:57:57 +01:00
|
|
|
services.postgresql.package=postgresql-package;
|
2016-01-20 03:42:59 +01:00
|
|
|
services.postgresql.enable = true;
|
2017-07-15 15:54:42 +02:00
|
|
|
services.postgresql.initialScript = pkgs.writeText "init.sql" ''
|
|
|
|
CREATE USER root WITH SUPERUSER;
|
|
|
|
'';
|
2016-01-20 03:42:59 +01:00
|
|
|
};
|
|
|
|
|
2017-02-11 05:57:57 +01:00
|
|
|
testScript = ''
|
|
|
|
$machine->start;
|
|
|
|
$machine->waitForUnit("postgresql");
|
|
|
|
# postgresql should be available just after unit start
|
|
|
|
$machine->succeed("cat ${test-sql} | psql postgres");
|
|
|
|
$machine->shutdown; # make sure that postgresql survive restart (bug #1735)
|
|
|
|
sleep(2);
|
|
|
|
$machine->start;
|
|
|
|
$machine->waitForUnit("postgresql");
|
|
|
|
$machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 3');
|
|
|
|
$machine->succeed('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 5');
|
|
|
|
$machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 4');
|
2017-07-15 15:58:17 +02:00
|
|
|
$machine->succeed('test $(psql postgres -tAc "SELECT xpath(\'/test/text()\', doc) FROM xmltest;"|wc -l) -eq 1');
|
2017-02-11 05:57:57 +01:00
|
|
|
$machine->shutdown;
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
in
|
|
|
|
mapAttrs' (p-name: p-package: {name=p-name; value=make-postgresql-test p-name p-package;}) postgresql-versions
|