2018-07-13 03:26:48 +02:00
|
|
|
setup() {
|
2018-07-15 06:43:11 +02:00
|
|
|
|
2021-01-03 23:55:02 +01:00
|
|
|
# declare some constants
|
|
|
|
readonly BN_REMOTEUSER="vagrant"
|
|
|
|
readonly BN_REMOTEHOST="bntest1"
|
|
|
|
readonly BN_BACKUPDIR="/var/backups"
|
|
|
|
readonly BN_SRCDIR="/var/cache/bntest"
|
|
|
|
|
2018-07-15 06:43:11 +02:00
|
|
|
# Write a basic backupninja config file
|
2018-07-13 03:26:48 +02:00
|
|
|
cat << EOF > "${BATS_TMPDIR}/backupninja.conf"
|
|
|
|
when = manual
|
2018-07-15 06:43:11 +02:00
|
|
|
loglevel = 5
|
2018-07-13 03:26:48 +02:00
|
|
|
reportemail = root
|
|
|
|
reportsuccess = yes
|
|
|
|
reportinfo = no
|
|
|
|
reportwarning = yes
|
|
|
|
reportspace = no
|
|
|
|
reporthost =
|
|
|
|
reportuser = ninja
|
|
|
|
reportdirectory = /var/lib/backupninja/reports
|
|
|
|
admingroup = root
|
|
|
|
logfile = ${BATS_TMPDIR}/log/backupninja.log
|
|
|
|
configdirectory = ${BATS_TMPDIR}/backup.d
|
|
|
|
scriptdirectory = /usr/share/backupninja
|
|
|
|
libdirectory = /usr/lib/backupninja
|
|
|
|
usecolors = no
|
|
|
|
EOF
|
|
|
|
|
2018-07-15 06:44:34 +02:00
|
|
|
# Create backupninja directories
|
2018-07-13 03:26:48 +02:00
|
|
|
mkdir "${BATS_TMPDIR}/log" "${BATS_TMPDIR}/backup.d"
|
|
|
|
chmod 0750 "${BATS_TMPDIR}/backup.d"
|
2018-07-15 06:44:34 +02:00
|
|
|
|
|
|
|
# Get name of component being tested
|
|
|
|
COMP=$(basename -s .bats "${BATS_TEST_FILENAME}")
|
|
|
|
|
|
|
|
# Invoke component-specific general test setup
|
|
|
|
# (runs only before the first test case)
|
|
|
|
if [[ "$BATS_TEST_NUMBER" -eq 1 ]]; then
|
|
|
|
if type "begin_${COMP}" 2>&1 | grep -q "function"; then
|
|
|
|
begin_${COMP}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Invoke component-specific test setup
|
|
|
|
if type "setup_${COMP}" 2>&1 | grep -q "function"; then
|
|
|
|
setup_${COMP}
|
|
|
|
fi
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2018-07-15 06:43:11 +02:00
|
|
|
|
|
|
|
# Print the debug log in case the test case fails
|
2020-12-31 05:29:24 +01:00
|
|
|
if [ -f "${BATS_TMPDIR}/log/backupninja.log" ]; then
|
|
|
|
echo "cat ${BATS_TMPDIR}/log/backupninja.log :"
|
|
|
|
cat "${BATS_TMPDIR}/log/backupninja.log"
|
|
|
|
# Copy logfile so it can be examined in subsequent tests
|
|
|
|
cp "${BATS_TMPDIR}/log/backupninja.log" "${BATS_TMPDIR}/_backupninja.log"
|
|
|
|
else
|
|
|
|
echo "backupninja.log not found"
|
|
|
|
fi
|
2018-07-15 06:43:11 +02:00
|
|
|
|
2018-07-13 03:26:48 +02:00
|
|
|
# Clean up
|
|
|
|
rm -rf "${BATS_TMPDIR}/backupninja.conf" \
|
|
|
|
"${BATS_TMPDIR}/log" \
|
|
|
|
"${BATS_TMPDIR}/backup.d" \
|
2018-07-15 06:44:34 +02:00
|
|
|
/var/mail/vagrant
|
|
|
|
|
|
|
|
# Invoke component-specific test teardown
|
|
|
|
if type "teardown_${COMP}" 2>&1 | grep -q "function"; then
|
|
|
|
teardown_${COMP}
|
|
|
|
fi
|
|
|
|
|
2020-12-31 05:27:57 +01:00
|
|
|
# Invoke component-specific general test teardown
|
|
|
|
# (runs only after the last test case)
|
2018-07-15 06:44:34 +02:00
|
|
|
if [[ "${#BATS_TEST_NAMES[@]}" -eq "$BATS_TEST_NUMBER" ]]; then
|
|
|
|
if type "finish_${COMP}" 2>&1 | grep -q "function"; then
|
|
|
|
finish_${COMP}
|
|
|
|
fi
|
|
|
|
fi
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setconfig() {
|
2020-12-31 05:28:19 +01:00
|
|
|
if [ -z $4 ]; then
|
2020-12-31 17:31:59 +01:00
|
|
|
crudini --set "${BATS_TMPDIR}/$1" '' $2 "$3"
|
2018-07-13 03:26:48 +02:00
|
|
|
else
|
2020-12-31 17:31:59 +01:00
|
|
|
crudini --set "${BATS_TMPDIR}/$1" $2 $3 "$4"
|
2018-07-13 03:26:48 +02:00
|
|
|
fi
|
|
|
|
}
|
2021-01-01 00:54:47 +01:00
|
|
|
|
|
|
|
remote_command() {
|
|
|
|
ssh vagrant@bntest1 "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup_backups() {
|
2021-01-02 21:47:40 +01:00
|
|
|
for c in "$@"; do
|
|
|
|
case "$c" in
|
|
|
|
"local")
|
|
|
|
umount /var/backups
|
|
|
|
mount -t tmpfs tmpfs /var/backups
|
|
|
|
;;
|
|
|
|
"remote")
|
|
|
|
remote_command "sudo umount /var/backups"
|
|
|
|
remote_command "sudo mount -t tmpfs tmpfs /var/backups"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2021-01-01 00:54:47 +01:00
|
|
|
}
|