summary refs log tree commit diff
path: root/nixos/tests/postgresql.nix
diff options
context:
space:
mode:
authorRodney Lorrimar <dev@rodney.id.au>2017-07-19 22:13:02 +0100
committerRodney Lorrimar <dev@rodney.id.au>2017-07-19 22:13:02 +0100
commit0b027720af00264b142e1ecade0e4fb576889909 (patch)
tree41e242d078b7674c4b86fba9b8f3f45189f9e08d /nixos/tests/postgresql.nix
parent502a272ee78727712c53d316cacba1b416e37d5e (diff)
downloadnixpkgs-0b027720af00264b142e1ecade0e4fb576889909.tar
nixpkgs-0b027720af00264b142e1ecade0e4fb576889909.tar.gz
nixpkgs-0b027720af00264b142e1ecade0e4fb576889909.tar.bz2
nixpkgs-0b027720af00264b142e1ecade0e4fb576889909.tar.lz
nixpkgs-0b027720af00264b142e1ecade0e4fb576889909.tar.xz
nixpkgs-0b027720af00264b142e1ecade0e4fb576889909.tar.zst
nixpkgs-0b027720af00264b142e1ecade0e4fb576889909.zip
nixos tests: run postgresql tests with postgres user
Diffstat (limited to 'nixos/tests/postgresql.nix')
-rw-r--r--nixos/tests/postgresql.nix18
1 files changed, 10 insertions, 8 deletions
diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix
index 54e7ec9ba17..0ce37b55bb7 100644
--- a/nixos/tests/postgresql.nix
+++ b/nixos/tests/postgresql.nix
@@ -26,24 +26,26 @@ let
       {
         services.postgresql.package=postgresql-package;
         services.postgresql.enable = true;
-        services.postgresql.initialScript = pkgs.writeText "init.sql" ''
-          CREATE USER root WITH SUPERUSER;
-        '';
       };
 
     testScript = ''
+      sub check_count {
+        my ($select, $nlines) = @_;
+        return 'test $(sudo -u postgres psql postgres -tAc "' . $select . '"|wc -l) -eq ' . $nlines;
+      }
+
       $machine->start;
       $machine->waitForUnit("postgresql");
       # postgresql should be available just after unit start
-      $machine->succeed("cat ${test-sql} | psql postgres");
+      $machine->succeed("cat ${test-sql} | sudo -u postgres psql");
       $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->succeed('test $(psql postgres -tAc "SELECT xpath(\'/test/text()\', doc) FROM xmltest;"|wc -l) -eq 1');
+      $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));
       $machine->shutdown;
     '';