tests: use runaction and global vars in pqsql test

This commit is contained in:
Jerome Charaoui 2021-01-05 10:41:44 -05:00
parent a5ab1cbe78
commit 0cf6e0a3c8

View File

@ -13,7 +13,7 @@ begin_pgsql() {
setup_pgsql() {
cat << EOF > "${BATS_TMPDIR}/backup.d/test.pgsql"
databases = all
backupdir = /var/backups/postgres
backupdir = ${BN_BACKUPDIR}/postgres
compress = yes
format = plain
EOF
@ -29,141 +29,141 @@ finish_pgsql() {
}
teardown_pgsql() {
rm -rf /var/backups/postgres
cleanup_backups local
}
@test "plain: exports all databases, with compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format plain
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
gzip -tq /var/backups/postgres/bntest0-all.sql.gz
gzip -tq "${BN_BACKUPDIR}/postgres/bntest0-all.sql.gz"
}
@test "plain: exports all databases, without compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format plain
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
[ -s /var/backups/postgres/bntest0-all.sql ]
[ -s "${BN_BACKUPDIR}/postgres/bntest0-all.sql" ]
}
@test "plain: exports specific database, with compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format plain
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
gzip -tq /var/backups/postgres/bntest_v11vJj.sql.gz
[ "$(zgrep -c -e '^COPY' /var/backups/postgres/bntest_v11vJj.sql.gz)" -eq 68 ]
[ ! -e /var/backups/postgres/bntest_p8Cz8k.sql.gz ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql.gz"
[ "$(zgrep -c -e '^COPY' ${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql.gz)" -eq 68 ]
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.sql.gz" ]
}
@test "plain: exports specific database, without compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format plain
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
[ -s /var/backups/postgres/bntest_v11vJj.sql ]
[ "$(grep -c -e '^COPY' /var/backups/postgres/bntest_v11vJj.sql)" -eq 68 ]
[ ! -e /var/backups/postgres/bntest_p8Cz8k.sql ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql" ]
[ "$(grep -c -e '^COPY' ${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql)" -eq 68 ]
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.sql" ]
}
@test "tar: exports all databases, with compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format tar
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
gzip -tq /var/backups/postgres/bntest_p8Cz8k.pg_dump.gz
gzip -tq /var/backups/postgres/bntest_v11vJj.pg_dump.gz
gzip -tq /var/backups/postgres/globals.sql.gz
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/globals.sql.gz"
}
@test "tar: exports all databases, without compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format tar
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
[ -s /var/backups/postgres/bntest_p8Cz8k.pg_dump ]
[ -s /var/backups/postgres/bntest_v11vJj.pg_dump ]
file /var/backups/postgres/bntest_p8Cz8k.pg_dump | grep "POSIX tar archive"
file /var/backups/postgres/bntest_v11vJj.pg_dump | grep "POSIX tar archive"
[ -s /var/backups/postgres/globals.sql ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file ${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump | grep "POSIX tar archive"
file ${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump | grep "POSIX tar archive"
[ -s "${BN_BACKUPDIR}/postgres/globals.sql" ]
}
@test "tar: exports specific database, with compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format tar
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
gzip -tq /var/backups/postgres/bntest_v11vJj.pg_dump.gz
[ ! -e /var/backups/postgres/bntest_p8Cz8k.pg_dump.gz ]
[ ! -e /var/backups/postgres/globals.sql.gz ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz" ]
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql.gz" ]
}
@test "tar: exports specific database, without compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format tar
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
[ -s /var/backups/postgres/bntest_v11vJj.pg_dump ]
file /var/backups/postgres/bntest_v11vJj.pg_dump | grep -q "POSIX tar archive"
[ ! -e /var/backups/postgres/bntest_p8Cz8k.pg_dump ]
[ ! -e /var/backups/postgres/globals.sql ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file ${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump | grep -q "POSIX tar archive"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql" ]
}
@test "custom: exports all databases, with compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format custom
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
gzip -tq /var/backups/postgres/bntest_p8Cz8k.pg_dump.gz
gzip -tq /var/backups/postgres/bntest_v11vJj.pg_dump.gz
gzip -tq /var/backups/postgres/globals.sql.gz
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/globals.sql.gz"
}
@test "custom: exports all databases, without compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format custom
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
[ -s /var/backups/postgres/bntest_p8Cz8k.pg_dump ]
[ -s /var/backups/postgres/bntest_v11vJj.pg_dump ]
file /var/backups/postgres/bntest_p8Cz8k.pg_dump | grep -q "PostgreSQL custom database dump"
file /var/backups/postgres/bntest_v11vJj.pg_dump | grep -q "PostgreSQL custom database dump"
[ -s /var/backups/postgres/globals.sql ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" | grep -q "PostgreSQL custom database dump"
file "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" | grep -q "PostgreSQL custom database dump"
[ -s "${BN_BACKUPDIR}/postgres/globals.sql" ]
}
@test "custom: exports specific database, with compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format custom
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
gzip -tq /var/backups/postgres/bntest_v11vJj.pg_dump.gz
[ ! -e /var/backups/postgres/bntest_p8Cz8k.pg_dump.gz ]
[ ! -e /var/backups/postgres/globals.sql.gz ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz" ]
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql.gz" ]
}
@test "custom: exports specific database, without compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format custom
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.pgsql"
runaction test.pgsql
[ "$status" -eq 0 ]
[ -s /var/backups/postgres/bntest_v11vJj.pg_dump ]
file /var/backups/postgres/bntest_v11vJj.pg_dump | grep -q "PostgreSQL custom database dump"
[ ! -e /var/backups/postgres/bntest_p8Cz8k.pg_dump ]
[ ! -e /var/backups/postgres/globals.sql ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" | grep -q "PostgreSQL custom database dump"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql" ]
}