Skip to content
Snippets Groups Projects
Commit 5bcaea00 authored by Jérôme Charaoui's avatar Jérôme Charaoui
Browse files

tests: use globals and common functions in tar test

parent 3733864b
No related branches found
No related tags found
1 merge request!46Add a testsuite
...@@ -2,8 +2,8 @@ load common ...@@ -2,8 +2,8 @@ load common
begin_tar() { begin_tar() {
apt-get -qq install debootstrap ncompress zstd apt-get -qq install debootstrap ncompress zstd
if [ ! -d /var/cache/bntest ]; then if [ ! -d "$BN_SRCDIR" ]; then
debootstrap --variant=minbase testing /var/cache/bntest debootstrap --variant=minbase testing "$BN_SRCDIR"
fi fi
} }
...@@ -11,10 +11,10 @@ setup_tar() { ...@@ -11,10 +11,10 @@ setup_tar() {
cat << EOF > "${BATS_TMPDIR}/backup.d/test.tar" cat << EOF > "${BATS_TMPDIR}/backup.d/test.tar"
when = manual when = manual
backupname = bntest backupname = bntest
backupdir = /var/backups/tartest backupdir = ${BN_BACKUPDIR}/tartest
compress = none compress = none
includes = /var/cache/bntest includes = $BN_SRCDIR
excludes = /var/cache/bntest/var excludes = ${BN_SRCDIR}/var
EOF EOF
chmod 0640 "${BATS_TMPDIR}/backup.d/test.tar" chmod 0640 "${BATS_TMPDIR}/backup.d/test.tar"
...@@ -26,9 +26,8 @@ teardown_tar() { ...@@ -26,9 +26,8 @@ teardown_tar() {
@test "no compression" { @test "no compression" {
runaction runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log" greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning."
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar) archive=$(find "${BN_BACKUPDIR}/tartest" -maxdepth 1 -name bntest-\*.tar)
echo $archive
[ -s "$archive" ] [ -s "$archive" ]
tar xOf "$archive" &> /dev/null tar xOf "$archive" &> /dev/null
} }
...@@ -36,8 +35,8 @@ teardown_tar() { ...@@ -36,8 +35,8 @@ teardown_tar() {
@test "compress compression" { @test "compress compression" {
setconfig compress compress setconfig compress compress
runaction runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log" greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning."
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.compress) archive=$(find "${BN_BACKUPDIR}/tartest" -maxdepth 1 -name bntest-\*.tar.compress)
[ -s "$archive" ] [ -s "$archive" ]
tar xZOf "$archive" &> /dev/null tar xZOf "$archive" &> /dev/null
} }
...@@ -45,8 +44,8 @@ teardown_tar() { ...@@ -45,8 +44,8 @@ teardown_tar() {
@test "gzip compression" { @test "gzip compression" {
setconfig compress gzip setconfig compress gzip
runaction runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log" greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning."
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tgz) archive=$(find "${BN_BACKUPDIR}/tartest" -maxdepth 1 -name bntest-\*.tgz)
[ -s "$archive" ] [ -s "$archive" ]
tar xzOf "$archive" &> /dev/null tar xzOf "$archive" &> /dev/null
} }
...@@ -54,8 +53,8 @@ teardown_tar() { ...@@ -54,8 +53,8 @@ teardown_tar() {
@test "bzip2 compression" { @test "bzip2 compression" {
setconfig compress bzip setconfig compress bzip
runaction runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log" greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning."
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.bz2) archive=$(find "${BN_BACKUPDIR}/tartest" -maxdepth 1 -name bntest-\*.tar.bz2)
[ -s "$archive" ] [ -s "$archive" ]
tar xjOf "$archive" &> /dev/null tar xjOf "$archive" &> /dev/null
} }
...@@ -63,8 +62,8 @@ teardown_tar() { ...@@ -63,8 +62,8 @@ teardown_tar() {
@test "xz compression" { @test "xz compression" {
setconfig compress xz setconfig compress xz
runaction runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log" greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning."
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.xz) archive=$(find "${BN_BACKUPDIR}/tartest" -maxdepth 1 -name bntest-\*.tar.xz)
[ -s "$archive" ] [ -s "$archive" ]
tar xJOf "$archive" &> /dev/null tar xJOf "$archive" &> /dev/null
} }
...@@ -72,8 +71,8 @@ teardown_tar() { ...@@ -72,8 +71,8 @@ teardown_tar() {
@test "zstd compression" { @test "zstd compression" {
setconfig compress zstd setconfig compress zstd
runaction runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log" greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning."
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.zst) archive=$(find "${BN_BACKUPDIR}/tartest" -maxdepth 1 -name bntest-\*.tar.zst)
[ -s "$archive" ] [ -s "$archive" ]
tar --zstd -xOf "$archive" &> /dev/null tar --zstd -xOf "$archive" &> /dev/null
} }
...@@ -81,8 +80,8 @@ teardown_tar() { ...@@ -81,8 +80,8 @@ teardown_tar() {
@test "unknown compression, defaults to gzip" { @test "unknown compression, defaults to gzip" {
setconfig compress foo setconfig compress foo
runaction runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 1 warning." "${BATS_TMPDIR}/log/backupninja.log" greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 1 warning."
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tgz) archive=$(find "${BN_BACKUPDIR}/tartest" -maxdepth 1 -name bntest-\*.tgz)
[ -s "$archive" ] [ -s "$archive" ]
tar xzOf "$archive" &> /dev/null tar xzOf "$archive" &> /dev/null
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment