2018-07-13 03:26:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# A minimal testsuite for backupninja
|
|
|
|
|
|
|
|
# This is meant to be run inside a development environment,
|
|
|
|
# so give the user a chance to bail
|
|
|
|
if [ ! -d "/vagrant" ]; then
|
|
|
|
read -p "This doesn't look like a test environment (Vagrant). Continue anyway? " -n 1 -r
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Are we root?
|
|
|
|
if [[ "$USER" != "root" ]]; then
|
|
|
|
echo "Please run the test suite as root."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Is backupninja in $PATH ?
|
|
|
|
if [ ! "$(which backupninja)" ]; then
|
|
|
|
echo "Couldn't find 'backupninja', is it installed?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install basic test dependencies
|
2020-12-31 05:28:19 +01:00
|
|
|
apt-get -qq install bats mailutils faketime crudini
|
2018-07-13 03:26:48 +02:00
|
|
|
|
|
|
|
# Create a temporary base directory
|
|
|
|
TMPDIR=$(mktemp -t -d bntest.XXXXXX)
|
|
|
|
export TMPDIR
|
|
|
|
|
2018-07-13 16:20:40 +02:00
|
|
|
# Mount temporary directories in tmpfs
|
|
|
|
# this should speed up the tests a little bit
|
|
|
|
mount -t tmpfs tmpfs "$TMPDIR"
|
|
|
|
mount -t tmpfs tmpfs /var/backups
|
|
|
|
|
2018-07-13 03:26:48 +02:00
|
|
|
# Run actual tests
|
2018-07-13 16:25:42 +02:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
for t in "$(dirname "$0")"/*.bats; do
|
|
|
|
echo "# $(basename -s .bats "$t")"
|
|
|
|
bats "$t"
|
|
|
|
echo
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "# $1"
|
|
|
|
bats "$(dirname "$0")/${1}.bats"
|
|
|
|
fi
|
|
|
|
|
2018-07-13 03:26:48 +02:00
|
|
|
|
|
|
|
# Clean up
|
2018-07-13 16:20:40 +02:00
|
|
|
umount "$TMPDIR"
|
|
|
|
umount /var/backups
|
|
|
|
rmdir "$TMPDIR"
|
2018-07-13 03:26:48 +02:00
|
|
|
|
|
|
|
exit 0
|