nixos tests: run postgresql tests with postgres user

+10 -8
+10 -8
nixos/tests/postgresql.nix
··· 26 26 { 27 27 services.postgresql.package=postgresql-package; 28 28 services.postgresql.enable = true; 29 - services.postgresql.initialScript = pkgs.writeText "init.sql" '' 30 - CREATE USER root WITH SUPERUSER; 31 - ''; 32 29 }; 33 30 34 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 + 35 37 $machine->start; 36 38 $machine->waitForUnit("postgresql"); 37 39 # postgresql should be available just after unit start 38 - $machine->succeed("cat ${test-sql} | psql postgres"); 40 + $machine->succeed("cat ${test-sql} | sudo -u postgres psql"); 39 41 $machine->shutdown; # make sure that postgresql survive restart (bug #1735) 40 42 sleep(2); 41 43 $machine->start; 42 44 $machine->waitForUnit("postgresql"); 43 - $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 3'); 44 - $machine->succeed('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 5'); 45 - $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 4'); 46 - $machine->succeed('test $(psql postgres -tAc "SELECT xpath(\'/test/text()\', doc) FROM xmltest;"|wc -l) -eq 1'); 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)); 47 49 $machine->shutdown; 48 50 ''; 49 51