nixosTests.postgres: Refactor code
This commit is contained in:
parent
f7b274d957
commit
fff1c2867f
@ -29,11 +29,15 @@ let
|
||||
|
||||
machine = {...}:
|
||||
{
|
||||
services.postgresql.enable = true;
|
||||
services.postgresql.package = postgresql-package;
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
package = postgresql-package;
|
||||
};
|
||||
|
||||
services.postgresqlBackup.enable = true;
|
||||
services.postgresqlBackup.databases = optional (!backup-all) "postgres";
|
||||
services.postgresqlBackup = {
|
||||
enable = true;
|
||||
databases = optional (!backup-all) "postgres";
|
||||
};
|
||||
};
|
||||
|
||||
testScript = let
|
||||
@ -49,23 +53,29 @@ let
|
||||
machine.start()
|
||||
machine.wait_for_unit("postgresql")
|
||||
|
||||
# postgresql should be available just after unit start
|
||||
with subtest("Postgresql is available just after unit start"):
|
||||
machine.succeed(
|
||||
"cat ${test-sql} | sudo -u postgres psql"
|
||||
)
|
||||
machine.shutdown() # make sure that postgresql survive restart (bug #1735)
|
||||
|
||||
with subtest("Postgresql survives restart (bug #1735)"):
|
||||
machine.shutdown()
|
||||
time.sleep(2)
|
||||
machine.start()
|
||||
machine.wait_for_unit("postgresql")
|
||||
|
||||
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))
|
||||
|
||||
# Check backup service
|
||||
machine.succeed("systemctl start ${backupService}.service")
|
||||
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")
|
||||
with subtest("Backup service works"):
|
||||
machine.succeed(
|
||||
"systemctl start ${backupService}.service",
|
||||
"zcat /var/backup/postgresql/${backupName}.sql.gz | grep '<test>ok</test>'",
|
||||
"stat -c '%a' /var/backup/postgresql/${backupName}.sql.gz | grep 600",
|
||||
)
|
||||
|
||||
machine.shutdown()
|
||||
'';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user