Refactor pre/post script tests

This commit is contained in:
ViViDboarder 2019-01-28 09:53:41 -08:00
parent b2d95cc775
commit aad79a458a
9 changed files with 47 additions and 33 deletions

View File

@ -1,4 +0,0 @@
set -e
# Clear dump
rm /data/dump.txt

View File

@ -1,3 +0,0 @@
set -e
cat /data/dump.txt > /mydb.txt

View File

@ -1,7 +0,0 @@
set -e
# Pretend we have some database
echo "insert foo into bar;" > /mydb.txt
# Let's dump that db
cat /mydb.txt > /data/dump.txt

View File

@ -9,10 +9,7 @@ if [ "$IN_CONTAINER" != "true" ] ; then
-e IN_CONTAINER=true \
-e SKIP_ON_START=true \
-v "$(pwd)/test-pre-scripts.sh:/test.sh" \
-v "$(pwd)/scripts/pre-backup.sh:/scripts/backup/before/1.sh" \
-v "$(pwd)/scripts/post-backup.sh:/scripts/backup/after/1.sh" \
-v "$(pwd)/scripts/pre-restore.sh:/scripts/restore/before/1.sh" \
-v "$(pwd)/scripts/post-restore.sh:/scripts/restore/after/1.sh" \
-v "$(pwd)/test-pre-scripts:/scripts" \
$image \
bash -c "/test.sh"
else
@ -22,45 +19,51 @@ else
type cron
type crontab
echo "Install sqlite3"
apt-get update
apt-get install -y --no-install-recommends sqlite3
echo "Create test data..."
mkdir -p /data && echo Test > /data/test.txt
mkdir -p /data
touch /data/test_database.db
sqlite3 /data/test_database.db < /scripts/create-test-data.sql
echo "Making backup..."
/backup.sh
echo "Verify intermediary file is gone"
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
echo "Delete test data..."
rm -fr /data/*
rm -fr /mydb.txt
echo "Verify deleted..."
test -f /data/test.txt && exit 1 || echo "Gone"
test -f /mydb.txt && exit 1 || echo "Gone"
test -f /data/test_database.db && exit 1 || echo "Gone"
echo "Restore backup..."
/restore.sh
echo "Verify pre-post script backups..."
test -f /mydb.txt
cat /mydb.txt
echo "Verify restored files exist..."
test -f /data/test_database.db
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
sqlite3 /data/test_database.db "select data from test_table where id = 1"
echo "Delete test data again..."
rm -fr /data/*
rm -fr /mydb.txt
echo "Verify deleted..."
test -f /data/test.txt && exit 1 || echo "Gone"
test -f /mydb.txt && exit 1 || echo "Gone"
test -f /data/test_database.db && exit 1 || echo "Gone"
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
RESTORE_ON_EMPTY_START=true /start.sh
echo "Verify restore happened..."
test -f /data/test.txt
cat /data/test.txt
test -f /data/test_database.db
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
sqlite3 /data/test_database.db "select data from test_table where id = 1"
echo "Verify pre-post script backups..."
test -f /mydb.txt
cat /mydb.txt
echo "Delete test data..."
rm -fr /data/*
echo "Verify restore with incorrect passphrase fails..."
echo "Fail to restore backup..."

View File

@ -0,0 +1,6 @@
set -e
cd /data
# Remove backed up copy
rm test_database.db.bak

View File

@ -0,0 +1,6 @@
set -e
cd /data
# Dump the SQLite database
sqlite3 test_database.db ".backup test_database.db.bak"

View File

@ -0,0 +1,7 @@
CREATE TABLE test_table (
id integer PRIMARY KEY,
data text NOT NULL
);
INSERT INTO test_table (data)
VALUES ("Test row");

View File

@ -0,0 +1,6 @@
set -e
cd /data
# Restore the backedup database
mv test_database.db.bak test_database.db