git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #22655 from spinus/postgresql-tests

test all postgresql versions, test server restart (#1735)

commita0d59165b9151e8e0b14e4e8b2c2cbc1be744a40 authorOliver Charles <ollie@ocharles.org.uk> dateFri 7 Apr 2017, 11:31 (10 years ago) parent78adf18a0d833d
2 files changed+42−22
nixos/release.nix+1−1 nixos/tests/postgresql.nix+41−21
nixos/release.nix+1−1
@@ -288,8 +288,8 @@ in rec {
288288 tests.pam-oath-login = callTest tests/pam-oath-login.nix {};
289289 #tests.panamax = hydraJob (import tests/panamax.nix { system = "x86_64-linux"; });
290290 tests.peerflix = callTest tests/peerflix.nix {};
291+ tests.postgresql = callSubTests tests/postgresql.nix {};
291292 tests.pgjwt = callTest tests/pgjwt.nix {};
292− tests.postgresql = callTest tests/postgresql.nix {};
293293 tests.printing = callTest tests/printing.nix {};
294294 tests.proxy = callTest tests/proxy.nix {};
295295 tests.pumpio = callTest tests/pump.io.nix {};
nixos/tests/postgresql.nix+41−21
@@ -1,26 +1,46 @@
1−import ./make-test.nix ({ pkgs, ...} : {
2− name = "postgresql";
3− meta = with pkgs.stdenv.lib.maintainers; {
4− maintainers = [ zagy ];
5− };
6−
7− nodes = {
8− master =
9− { pkgs, config, ... }:
1+{ system ? builtins.currentSystem }:
2+with import ../lib/testing.nix { inherit system; };
3+with pkgs.lib;
4+let
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+ '';
17+ make-postgresql-test = postgresql-name: postgresql-package: {
18+ name = postgresql-name;
19+ meta = with pkgs.stdenv.lib.maintainers; {
20+ maintainers = [ zagy ];
21+ };
1022
23+ machine = {pkgs, config, ...}:
1124 {
25+ services.postgresql.package=postgresql-package;
1226 services.postgresql.enable = true;
13− services.postgresql.initialScript = pkgs.writeText "postgresql-init.sql"
14− ''
15− CREATE ROLE postgres WITH superuser login createdb;
16− '';
1727 };
18− };
1928
20− testScript = ''
21− startAll;
22− $master->waitForUnit("postgresql");
23− $master->sleep(10); # Hopefully this is long enough!!
24− $master->succeed("echo 'select 1' | sudo -u postgres psql");
25− '';
26−})
29+ testScript = ''
30+ $machine->start;
31+ $machine->waitForUnit("postgresql");
32+ # postgresql should be available just after unit start
33+ $machine->succeed("cat ${test-sql} | psql postgres");
34+ $machine->shutdown; # make sure that postgresql survive restart (bug #1735)
35+ sleep(2);
36+ $machine->start;
37+ $machine->waitForUnit("postgresql");
38+ $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 3');
39+ $machine->succeed('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 5');
40+ $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 4');
41+ $machine->shutdown;
42+ '';
43+
44+ };
45+in
46+ mapAttrs' (p-name: p-package: {name=p-name; value=make-postgresql-test p-name p-package;}) postgresql-versions