1{ system ? builtins.currentSystem }:
2with import ../lib/testing.nix { inherit system; };
3with pkgs.lib;
4let
5 postgresql-versions = pkgs.callPackages ../../pkgs/servers/sql/postgresql { };
6 test-sql = pkgs.writeText "postgresql-test" ''
7 CREATE EXTENSION pgcrypto; -- just to check if lib loading works
8 CREATE TABLE sth (
9 id int
10 );
11 INSERT INTO sth (id) VALUES (1);
12 INSERT INTO sth (id) VALUES (1);
13 INSERT INTO sth (id) VALUES (1);
14 INSERT INTO sth (id) VALUES (1);
15 INSERT INTO sth (id) VALUES (1);
16 CREATE TABLE xmltest ( doc xml );
17 INSERT INTO xmltest (doc) VALUES ('<test>ok</test>'); -- check if libxml2 enabled
18 '';
19 make-postgresql-test = postgresql-name: postgresql-package: makeTest {
20 name = postgresql-name;
21 meta = with pkgs.stdenv.lib.maintainers; {
22 maintainers = [ zagy ];
23 };
24
25 machine = {pkgs, config, ...}:
26 {
27 services.postgresql.package=postgresql-package;
28 services.postgresql.enable = true;
29 };
30
31 testScript = ''
32 sub check_count {
33 my ($select, $nlines) = @_;
34 return 'test $(sudo -u postgres psql postgres -tAc "' . $select . '"|wc -l) -eq ' . $nlines;
35 }
36
37 $machine->start;
38 $machine->waitForUnit("postgresql");
39 # postgresql should be available just after unit start
40 $machine->succeed("cat ${test-sql} | sudo -u postgres psql");
41 $machine->shutdown; # make sure that postgresql survive restart (bug #1735)
42 sleep(2);
43 $machine->start;
44 $machine->waitForUnit("postgresql");
45 $machine->fail(check_count("SELECT * FROM sth;", 3));
46 $machine->succeed(check_count("SELECT * FROM sth;", 5));
47 $machine->fail(check_count("SELECT * FROM sth;", 4));
48 $machine->succeed(check_count("SELECT xpath(\'/test/text()\', doc) FROM xmltest;", 1));
49 $machine->shutdown;
50 '';
51
52 };
53in
54 mapAttrs' (p-name: p-package: {name=p-name; value=make-postgresql-test p-name p-package;}) postgresql-versions