summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorTomasz Czyż <tomasz.czyz@gmail.com>2017-02-11 04:57:57 +0000
committerTomasz Czyż <tomasz.czyz@gmail.com>2017-02-21 22:48:39 +0000
commitab22a0803996c40eee80aa0f81d151090ab15b01 (patch)
treeb782fe24727d6b2b39945f025d20546695861759 /nixos/tests
parent5e8499f4472b552131c905e2fe81ec8b28a3843c (diff)
downloadnixpkgs-ab22a0803996c40eee80aa0f81d151090ab15b01.tar
nixpkgs-ab22a0803996c40eee80aa0f81d151090ab15b01.tar.gz
nixpkgs-ab22a0803996c40eee80aa0f81d151090ab15b01.tar.bz2
nixpkgs-ab22a0803996c40eee80aa0f81d151090ab15b01.tar.lz
nixpkgs-ab22a0803996c40eee80aa0f81d151090ab15b01.tar.xz
nixpkgs-ab22a0803996c40eee80aa0f81d151090ab15b01.tar.zst
nixpkgs-ab22a0803996c40eee80aa0f81d151090ab15b01.zip
test all postgresql versions, test server restart (#1735)
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/postgresql.nix62
1 files changed, 41 insertions, 21 deletions
diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix
index f17384b44ba..1f4f43a2666 100644
--- a/nixos/tests/postgresql.nix
+++ b/nixos/tests/postgresql.nix
@@ -1,26 +1,46 @@
-import ./make-test.nix ({ pkgs, ...} : {
-  name = "postgresql";
-  meta = with pkgs.stdenv.lib.maintainers; {
-    maintainers = [ zagy ];
-  };
-
-  nodes = {
-    master =
-      { pkgs, config, ... }:
+{ 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);
+  '';
+  make-postgresql-test = postgresql-name: postgresql-package: {
+    name = postgresql-name;
+    meta = with pkgs.stdenv.lib.maintainers; {
+      maintainers = [ zagy ];
+    };
 
+    machine = {pkgs, config, ...}:
       {
+        services.postgresql.package=postgresql-package;
         services.postgresql.enable = true;
-        services.postgresql.initialScript =  pkgs.writeText "postgresql-init.sql"
-          ''
-          CREATE ROLE postgres WITH superuser login createdb;
-          '';
       };
-  };
 
-  testScript = ''
-    startAll;
-    $master->waitForUnit("postgresql");
-    $master->sleep(10); # Hopefully this is long enough!!
-    $master->succeed("echo 'select 1' | sudo -u postgres psql");
-  '';
-})
+    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');
+      $machine->shutdown;
+    '';
+
+  };
+in
+  mapAttrs' (p-name: p-package: {name=p-name; value=make-postgresql-test p-name p-package;}) postgresql-versions