nixos/postgres: Port test to python
This commit is contained in:
parent
75d3e810d6
commit
8eead58520
|
@ -3,7 +3,7 @@
|
||||||
pkgs ? import ../.. { inherit system config; }
|
pkgs ? import ../.. { inherit system config; }
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with import ../lib/testing.nix { inherit system pkgs; };
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -40,29 +40,33 @@ let
|
||||||
backupName = if backup-all then "all" else "postgres";
|
backupName = if backup-all then "all" else "postgres";
|
||||||
backupService = if backup-all then "postgresqlBackup" else "postgresqlBackup-postgres";
|
backupService = if backup-all then "postgresqlBackup" else "postgresqlBackup-postgres";
|
||||||
in ''
|
in ''
|
||||||
sub check_count {
|
def check_count(statement, lines):
|
||||||
my ($select, $nlines) = @_;
|
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
|
||||||
return 'test $(sudo -u postgres psql postgres -tAc "' . $select . '"|wc -l) -eq ' . $nlines;
|
statement, lines
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
|
machine.start()
|
||||||
|
machine.wait_for_unit("postgresql")
|
||||||
|
|
||||||
$machine->start;
|
|
||||||
$machine->waitForUnit("postgresql");
|
|
||||||
# postgresql should be available just after unit start
|
# postgresql should be available just after unit start
|
||||||
$machine->succeed("cat ${test-sql} | sudo -u postgres psql");
|
machine.succeed(
|
||||||
$machine->shutdown; # make sure that postgresql survive restart (bug #1735)
|
"cat ${test-sql} | sudo -u postgres psql"
|
||||||
sleep(2);
|
)
|
||||||
$machine->start;
|
machine.shutdown() # make sure that postgresql survive restart (bug #1735)
|
||||||
$machine->waitForUnit("postgresql");
|
time.sleep(2)
|
||||||
$machine->fail(check_count("SELECT * FROM sth;", 3));
|
machine.start()
|
||||||
$machine->succeed(check_count("SELECT * FROM sth;", 5));
|
machine.wait_for_unit("postgresql")
|
||||||
$machine->fail(check_count("SELECT * FROM sth;", 4));
|
machine.fail(check_count("SELECT * FROM sth;", 3))
|
||||||
$machine->succeed(check_count("SELECT xpath(\'/test/text()\', doc) FROM xmltest;", 1));
|
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))
|
||||||
|
|
||||||
# Check backup service
|
# Check backup service
|
||||||
$machine->succeed("systemctl start ${backupService}.service");
|
machine.succeed("systemctl start ${backupService}.service")
|
||||||
$machine->succeed("zcat /var/backup/postgresql/${backupName}.sql.gz | grep '<test>ok</test>'");
|
machine.succeed("zcat /var/backup/postgresql/${backupName}.sql.gz | grep '<test>ok</test>'")
|
||||||
$machine->succeed("stat -c '%a' /var/backup/postgresql/${backupName}.sql.gz | grep 600");
|
machine.succeed("stat -c '%a' /var/backup/postgresql/${backupName}.sql.gz | grep 600")
|
||||||
$machine->shutdown;
|
machine.shutdown()
|
||||||
'';
|
'';
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue