2018-05-13 17:31:31 +00:00
|
|
|
#! /bin/bash
|
2020-02-14 20:12:07 +00:00
|
|
|
set -euf
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
|
2020-02-14 20:12:07 +00:00
|
|
|
if [ -z "${IN_CONTAINER+x}" ] ; then
|
2018-05-13 17:31:31 +00:00
|
|
|
# Run the test script within the container
|
2020-02-14 20:12:07 +00:00
|
|
|
image="$1"
|
2018-05-13 17:31:31 +00:00
|
|
|
docker run --rm \
|
|
|
|
-e IN_CONTAINER=true \
|
|
|
|
-e SKIP_ON_START=true \
|
|
|
|
-v "$(pwd)/test.sh:/test.sh" \
|
2020-02-11 21:28:19 +00:00
|
|
|
"$image" \
|
2018-05-13 17:31:31 +00:00
|
|
|
bash -c "/test.sh"
|
|
|
|
else
|
2020-02-13 01:43:36 +00:00
|
|
|
# Optionally sleep at beginning for compose tests that may need it
|
|
|
|
sleep "${SLEEP:-0}"
|
|
|
|
|
2018-05-13 17:31:31 +00:00
|
|
|
echo "Performing backup tests"
|
|
|
|
|
|
|
|
echo "Verify cron and crontab exist"
|
|
|
|
type cron
|
|
|
|
type crontab
|
|
|
|
|
|
|
|
echo "Create test data..."
|
|
|
|
mkdir -p /data && echo Test > /data/test.txt
|
|
|
|
|
|
|
|
echo "Making backup..."
|
2019-02-01 22:01:51 +00:00
|
|
|
/cron-exec.sh /backup.sh || { cat /cron.log && exit 1; }
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
echo "Verify backup..."
|
2019-02-01 22:01:51 +00:00
|
|
|
/cron-exec.sh /verify.sh || { cat /cron.log && exit 1; }
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
echo "Delete test data..."
|
2020-02-14 20:12:07 +00:00
|
|
|
rm -fr /data/test.txt
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
echo "Verify deleted..."
|
|
|
|
test -f /data/test.txt && exit 1 || echo "Gone"
|
|
|
|
|
|
|
|
echo "Restore backup..."
|
2019-02-01 22:01:51 +00:00
|
|
|
/cron-exec.sh /restore.sh || { cat /cron.log && exit 1; }
|
|
|
|
/healthcheck.sh || { cat /cron.log && exit 1; }
|
2018-05-13 17:31:31 +00:00
|
|
|
|
2018-08-10 18:20:47 +00:00
|
|
|
echo "Verify restore..."
|
|
|
|
test -f /data/test.txt
|
|
|
|
cat /data/test.txt
|
|
|
|
|
2018-05-13 17:31:31 +00:00
|
|
|
echo "Verify backup..."
|
2019-02-01 22:01:51 +00:00
|
|
|
/cron-exec.sh /verify.sh || { cat /cron.log && exit 1; }
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
echo "Delete test data again..."
|
2020-02-14 20:12:07 +00:00
|
|
|
rm -fr /data/test.txt
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
echo "Verify deleted..."
|
|
|
|
test -f /data/test.txt && exit 1 || echo "Gone"
|
|
|
|
|
|
|
|
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
|
2019-02-01 22:01:51 +00:00
|
|
|
RESTORE_ON_EMPTY_START=true /start.sh || { cat /cron.log && exit 1; }
|
|
|
|
/healthcheck.sh || { cat /cron.log && exit 1; }
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
echo "Verify restore happened..."
|
|
|
|
test -f /data/test.txt
|
2018-08-10 18:20:47 +00:00
|
|
|
cat /data/test.txt
|
2018-05-13 17:31:31 +00:00
|
|
|
|
|
|
|
echo "Verify restore with incorrect passphrase fails..."
|
|
|
|
echo "Fail to restore backup..."
|
2019-02-01 21:48:00 +00:00
|
|
|
PASSPHRASE=Incorrect.Mule.Solar.Paperclip /cron-exec.sh /restore.sh && exit 1 || echo "OK"
|
|
|
|
|
|
|
|
echo "Verify failed healthcheck"
|
|
|
|
/healthcheck.sh && exit 1 || echo "OK"
|
2018-05-13 17:31:31 +00:00
|
|
|
fi
|