1
0
mirror of https://github.com/deajan/obackup.git synced 2024-11-14 19:53:42 +01:00
obackup/dev/tests/run_tests.sh

643 lines
20 KiB
Bash
Raw Normal View History

2016-08-18 14:19:52 +02:00
#!/usr/bin/env bash
2016-09-04 21:37:24 +02:00
## obackup basic tests suite 2016090403
2016-09-02 13:13:53 +02:00
2016-09-09 12:36:30 +02:00
#TODO: add old conf file, have upgrade and check
2016-09-02 13:13:53 +02:00
#TODO: Must recreate files before each test set
2016-08-18 14:19:52 +02:00
2016-08-30 16:12:10 +02:00
OBACKUP_DIR="$(pwd)"
OBACKUP_DIR=${OBACKUP_DIR%%/dev*}
DEV_DIR="$OBACKUP_DIR/dev"
TESTS_DIR="$DEV_DIR/tests"
2016-09-02 13:22:24 +02:00
2016-09-02 16:08:23 +02:00
if [ "$TRAVIS_RUN" == true ]; then
echo "Running with travis settings"
2016-09-02 13:27:39 +02:00
CONF_DIR="$TESTS_DIR/conf-travis"
2016-09-02 16:08:23 +02:00
else
echo "Running with local settings"
CONF_DIR="$TESTS_DIR/conf-local"
2016-09-02 13:22:24 +02:00
fi
2016-09-02 13:13:53 +02:00
LOCAL_CONF="local.conf"
PULL_CONF="pull.conf"
PUSH_CONF="push.conf"
2016-09-09 12:36:30 +02:00
OLD_CONF="old.conf"
2016-08-18 14:19:52 +02:00
2016-08-30 18:12:59 +02:00
OBACKUP_EXECUTABLE=obackup.sh
2016-09-09 12:36:30 +02:00
OBACKUP_UPGRADE=upgrade-v1.x-2.1x.sh
2016-08-30 18:12:59 +02:00
2016-08-30 16:12:10 +02:00
SOURCE_DIR="${HOME}/obackup-testdata"
TARGET_DIR="${HOME}/obackup-storage"
2016-08-18 14:19:52 +02:00
2016-08-30 19:17:14 +02:00
TARGET_DIR_SQL_LOCAL="$TARGET_DIR/sql"
TARGET_DIR_FILE_LOCAL="$TARGET_DIR/files"
2016-08-18 14:19:52 +02:00
2016-08-30 19:17:14 +02:00
TARGET_DIR_SQL_PULL="$TARGET_DIR/sql-pull"
TARGET_DIR_FILE_PULL="$TARGET_DIR/files-pull"
2016-08-18 14:19:52 +02:00
2016-08-30 19:17:14 +02:00
TARGET_DIR_SQL_PUSH="$TARGET_DIR/sql-push"
TARGET_DIR_FILE_PUSH="$TARGET_DIR/files-push"
2016-08-18 14:19:52 +02:00
2016-09-02 23:20:48 +02:00
TARGET_DIR_FILE_CRYPT="$TARGET_DIR/crypt"
2016-09-02 13:13:53 +02:00
2016-08-18 17:10:53 +02:00
SIMPLE_DIR="testData"
RECURSIVE_DIR="testDataRecursive"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
S_DIR_1="dir rect ory"
R_EXCLUDED_DIR="Excluded"
R_DIR_1="a"
R_DIR_2="b"
R_DIR_3="c d"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
S_FILE_1="some file"
R_FILE_1="file_1"
R_FILE_2="file 2"
R_FILE_3="file 3"
2016-09-02 13:13:53 +02:00
N_FILE_1="non recurse file"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
EXCLUDED_FILE="exclu.ded"
DATABASE_1="mysql.sql.xz"
DATABASE_2="performance_schema.sql.xz"
DATABASE_EXCLUDED="information_schema.sql.xz"
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
CRYPT_EXTENSION=".obackup.gpg"
ROTATE_1_EXTENSION=".obackup.1"
PASSFILE="passfile"
2016-09-04 21:37:24 +02:00
CRYPT_TEST_FILE="testfile"
2016-09-02 13:13:53 +02:00
function SetStableToYes () {
if grep "^IS_STABLE=YES" "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" > /dev/null; then
IS_STABLE=yes
else
IS_STABLE=no
sed -i.tmp 's/^IS_STABLE=no/IS_STABLE=yes/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set stable to yes" "0" $?
fi
}
function SetStableToOrigin () {
if [ "$IS_STABLE" == "no" ]; then
sed -i.tmp 's/^IS_STABLE=yes/IS_STABLE=no/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set stable to origin value" "0" $?
fi
}
function SetEncryption () {
local confFile="${1}"
local value="${2}"
if [ $value == true ]; then
sed -i 's/^ENCRYPTION=no/ENCRYPTION=yes/' "$confFile"
assertEquals "Enable encryption in $file" "0" $?
else
sed -i 's/^ENCRYPTION=yes/ENCRYPTION=no/' "$confFile"
assertEquals "Disable encryption in $file" "0" $?
fi
}
function SetupGPG {
2016-09-02 13:22:24 +02:00
if type gpg2 > /dev/null; then
2016-09-04 21:37:24 +02:00
CRYPT_TOOL=gpg2
2016-09-02 13:22:24 +02:00
elif type gpg > /dev/null; then
2016-09-04 21:37:24 +02:00
CRYPT_TOOL=gpg
2016-09-02 13:22:24 +02:00
else
echo "No gpg support"
fi
2016-09-04 21:37:24 +02:00
if ! $CRYPT_TOOL --list-keys | grep "John Doe" > /dev/null; then
2016-09-02 13:13:53 +02:00
cat >gpgcommand <<EOF
%echo Generating a GPG Key
Key-Type: RSA
Key-Length: 4096
Name-Real: John Doe
Name-Comment: obackup-test-key
Name-Email: john@example.com
Expire-Date: 0
Passphrase: PassPhrase123
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
2016-09-02 16:33:49 +02:00
if type apt-get > /dev/null 2>&1; then
sudo apt-get install rng-tools
2016-09-02 16:33:49 +02:00
fi
2016-09-02 13:13:53 +02:00
# Setup fast entropy
2016-09-04 08:37:21 +02:00
if type rngd > /dev/null 2>&1; then
rngd -r /dev/urandom
2016-09-02 13:22:24 +02:00
else
2016-09-04 08:37:21 +02:00
echo "No rngd support"
2016-09-02 13:13:53 +02:00
fi
2016-09-04 21:37:24 +02:00
$CRYPT_TOOL --batch --gen-key gpgcommand
echo "Currently owned $CRYPT_TOOL keys"
echo $($CRYPT_TOOL --list-keys)
2016-09-02 13:13:53 +02:00
rm -f gpgcommand
fi
echo "PassPhrase123" > "$TESTS_DIR/$PASSFILE"
}
function SetupSSH {
echo -e 'y\n'| ssh-keygen -t rsa -b 2048 -N "" -f "${HOME}/.ssh/id_rsa_local"
cat "${HOME}/.ssh/id_rsa_local.pub" >> "${HOME}/.ssh/authorized_keys"
chmod 600 "${HOME}/.ssh/authorized_keys"
# Add localhost to known hosts so self connect works
if [ -z $(ssh-keygen -F localhost) ]; then
ssh-keyscan -H localhost >> ~/.ssh/known_hosts
fi
2016-09-02 13:13:53 +02:00
}
2016-08-18 14:19:52 +02:00
function oneTimeSetUp () {
source "$DEV_DIR/ofunctions.sh"
2016-09-02 13:13:53 +02:00
SetupGPG
SetupSSH
}
2016-09-02 13:38:35 +02:00
function setUp () {
2016-09-02 13:13:53 +02:00
rm -rf "$SOURCE_DIR"
2016-09-04 21:11:05 +02:00
rm -rf "$TARGET_DIR"
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
mkdir -p "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_EXCLUDED_DIR"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2"
mkdir -p "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3"
touch "$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
touch "$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE"
2016-09-02 13:13:53 +02:00
touch "$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
2016-08-18 17:10:53 +02:00
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
dd if=/dev/urandom of="$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3" bs=1M count=2
touch "$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$EXCLUDED_FILE"
FilePresence=(
"$SOURCE_DIR/$SIMPLE_DIR/$S_DIR_1/$S_FILE_1"
2016-09-02 13:13:53 +02:00
"$SOURCE_DIR/$RECURSIVE_DIR/$N_FILE_1"
2016-08-18 17:10:53 +02:00
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_1/$R_FILE_1"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_2/$R_FILE_2"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_FILE_3"
)
DatabasePresence=(
"$DATABASE_1"
"$DATABASE_2"
)
FileExcluded=(
"$SOURCE_DIR/$SIMPLE_DIR/$EXCLUDED_FILE"
"$SOURCE_DIR/$RECURSIVE_DIR/$R_DIR_3/$R_EXCLUDED_FILE"
)
DatabaseExcluded=(
"$DATABASE_EXCLUDED"
)
DirectoriesExcluded=(
"$RECURSIVE_DIR/$R_EXCLUDED_DIR"
)
2016-08-18 14:19:52 +02:00
}
function oneTimeTearDown () {
2016-09-02 13:13:53 +02:00
SetStableToOrigin
2016-08-18 14:19:52 +02:00
}
2016-08-30 16:26:30 +02:00
function test_Merge () {
cd "$DEV_DIR"
./merge.sh
assertEquals "Merging code" "0" $?
2016-09-02 13:13:53 +02:00
SetStableToYes
2016-08-30 16:26:30 +02:00
}
2016-08-18 17:10:53 +02:00
2016-09-04 22:48:09 +02:00
# Keep this function to check Travis environment GPG behavior
function disabled_test_GPG () {
2016-09-04 22:20:18 +02:00
echo "Encrypting file"
2016-09-04 21:37:24 +02:00
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TEST_FILE$CRYPT_EXTENSION" --recipient "John Doe" --batch --yes --encrypt "$TESTS_DIR/$PASSFILE"
assertEquals "Encrypt file" "0" $?
2016-09-04 22:20:18 +02:00
echo "Decrypt using passphrase file"
2016-09-04 21:37:24 +02:00
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TEST_FILE" --batch --yes --passphrase-file="$TESTS_DIR/$PASSFILE" --decrypt "$TESTS_DIR/$CRYPT_TEST_FILE$CRYPT_EXTENSION"
assertEquals "Decrypt file using passfile" "0" $?
2016-09-04 22:20:18 +02:00
echo "Decrypt using passphrase"
2016-09-04 21:41:05 +02:00
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TEST_FILE" --batch --yes --passphrase PassPhrase123 --decrypt "$TESTS_DIR/$CRYPT_TEST_FILE$CRYPT_EXTENSION"
2016-09-04 21:37:24 +02:00
assertEquals "Decrypt file using passphrase" "0" $?
2016-09-04 22:20:18 +02:00
echo "Decrypt using passphrase file with cat"
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TEST_FILE" --batch --yes --passphrase $(cat "$TESTS_DIR/$PASSFILE") --decrypt "$TESTS_DIR/$CRYPT_TEST_FILE$CRYPT_EXTENSION"
assertEquals "Decrypt file using passphrase" "0" $?
echo "Decrypt using passphrase file --no-use-agent"
2016-09-04 22:25:24 +02:00
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TEST_FILE" --no-use-agent --batch --yes --passphrase-file="$TESTS_DIR/$PASSFILE" --decrypt "$TESTS_DIR/$CRYPT_TEST_FILE$CRYPT_EXTENSION"
2016-09-04 22:20:18 +02:00
assertEquals "Decrypt file using passphrase" "0" $?
echo "Decrypt using passphrase --no-use-agent"
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TEST_FILE" --no-use-agent --batch --yes --passphrase PassPhrase123 --decrypt "$TESTS_DIR/$CRYPT_TEST_FILE$CRYPT_EXTENSION"
assertEquals "Decrypt file using passphrase" "0" $?
echo "Decrypt using passphrase file with cat --no-use-agent"
$CRYPT_TOOL --out "$TESTS_DIR/$CRYPT_TEST_FILE" --no-use-agent --batch --yes --passphrase $(cat "$TESTS_DIR/$PASSFILE") --decrypt "$TESTS_DIR/$CRYPT_TEST_FILE$CRYPT_EXTENSION"
assertEquals "Decrypt file using passphrase" "0" $?
2016-09-04 21:37:24 +02:00
}
2016-09-02 23:22:29 +02:00
function test_LocalRun () {
SetEncryption "$CONF_DIR/$LOCAL_CONF" false
2016-08-18 14:19:52 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-09-02 13:13:53 +02:00
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_LOCAL/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_LOCAL/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_LOCAL/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_LOCAL/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_LOCAL/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_LOCAL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $?
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${DatabasePresence[@]}"; do
2016-09-02 13:13:53 +02:00
[ -f "$TARGET_DIR_SQL_LOCAL/$file$ROTATE_1_EXTENSION" ]
2016-08-18 17:10:53 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $?
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
2016-08-18 14:19:52 +02:00
}
2016-08-30 19:17:14 +02:00
2016-09-02 23:22:29 +02:00
function test_PullRun () {
SetEncryption "$CONF_DIR/$LOCAL_CONF" false
2016-08-18 14:19:52 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-09-02 13:13:53 +02:00
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PULL/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_PULL/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_PULL/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PULL/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_PULL/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_PULL/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-09-02 13:13:53 +02:00
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${DatabasePresence[@]}"; do
2016-09-02 13:13:53 +02:00
[ -f "$TARGET_DIR_SQL_PULL/$file$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file$ROTATE_1_EXTENSION]" "0" $?
2016-08-18 17:10:53 +02:00
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
2016-08-18 14:19:52 +02:00
}
2016-09-02 23:22:29 +02:00
function test_PushRun () {
SetEncryption "$CONF_DIR/$LOCAL_CONF" false
2016-08-18 14:19:52 +02:00
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-09-02 13:13:53 +02:00
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PUSH/$file]" "0" $?
done
for file in "${FileExcluded[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file" ]
assertEquals "File Excluded [$TARGET_DIR_FILE_PUSH/$file]" "1" $?
done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PUSH/$file]" "0" $?
done
for file in "${DatabaseExcluded[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file" ]
assertEquals "Database Excluded [$TARGET_DIR_SQL_PUSH/$file]" "1" $?
done
for directory in "${DirectoriesExcluded[@]}"; do
[ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
# Tests presence of rotated files
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-09-02 13:13:53 +02:00
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
2016-08-18 14:19:52 +02:00
assertEquals "Return code" "0" $?
2016-08-18 17:10:53 +02:00
for file in "${DatabasePresence[@]}"; do
2016-09-02 13:13:53 +02:00
[ -f "$TARGET_DIR_SQL_PUSH/$file$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file$ROTATE_1_EXTENSION]" "0" $?
2016-08-18 17:10:53 +02:00
done
2016-08-18 14:19:52 +02:00
2016-09-02 13:13:53 +02:00
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION" ]
2016-09-04 21:11:05 +02:00
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
}
2016-09-02 23:22:29 +02:00
function test_EncryptLocalRun () {
2016-09-02 13:13:53 +02:00
SetEncryption "$CONF_DIR/$LOCAL_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
done
# TODO: Exclusion lists don't work with encrypted files yet
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_LOCAL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_LOCAL/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$LOCAL_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_LOCAL" --passphrase-file="$TESTS_DIR/$PASSFILE"
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt sql storage in [$TARGET_DIR_SQL_LOCAL]" "0" $?
2016-09-02 13:13:53 +02:00
2016-09-02 23:20:48 +02:00
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_CRYPT" --passphrase-file="$TESTS_DIR/$PASSFILE"
assertEquals "Decrypt file storage in [$TARGET_DIR_FILE_CRYPT]" "0" $?
2016-09-02 13:13:53 +02:00
SetEncryption "$CONF_DIR/$LOCAL_CONF" false
2016-09-02 13:13:53 +02:00
}
function test_EncryptPullRun () {
# Basic return code tests. Need to go deep into file presence testing
SetEncryption "$CONF_DIR/$PULL_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
2016-09-02 16:08:23 +02:00
[ -f "$TARGET_DIR_FILE_CRYPT/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_CRYPT/$file$CRYPT_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
done
# for file in "${FileExcluded[@]}"; do
2016-09-02 16:08:23 +02:00
# [ -f "$TARGET_DIR_FILE_CRYPT/$file$CRYPT_EXTENSION" ]
2016-09-02 13:13:53 +02:00
# assertEquals "File Excluded [$TARGET_DIR_FILE_PULL/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PULL/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PULL/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PULL_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
2016-09-03 14:18:03 +02:00
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
done
2016-09-02 16:08:23 +02:00
[ -d "$TARGET_DIR_FILE_CRYPT/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_CRYPT/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
2016-09-02 13:13:53 +02:00
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PULL" --passphrase-file="$TESTS_DIR/$PASSFILE"
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt sql storage in [$TARGET_DIR_SQL_PULL]" "0" $?
2016-09-02 13:13:53 +02:00
2016-09-02 16:08:23 +02:00
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_CRYPT" --passphrase-file="$TESTS_DIR/$PASSFILE"
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt file storage in [$TARGET_DIR_FILE_CRYPT]" "0" $?
2016-09-02 13:13:53 +02:00
SetEncryption "$CONF_DIR/$PULL_CONF" false
2016-09-02 13:13:53 +02:00
}
2016-09-02 23:22:29 +02:00
function test_EncryptPushRun () {
2016-09-02 13:13:53 +02:00
# Basic return code tests. Need to go deep into file presence testing
SetEncryption "$CONF_DIR/$PUSH_CONF" true
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${FilePresence[@]}"; do
[ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "File Presence [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${FileExcluded[@]}"; do
# [ -f "$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "File Excluded [$TARGET_DIR_FILE_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
assertEquals "Database Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
# for file in "${DatabaseExcluded[@]}"; do
# [ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION" ]
# assertEquals "Database Excluded [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "1" $?
# done
# for directory in "${DirectoriesExcluded[@]}"; do
# [ -d "$TARGET_DIR_FILE_PUSH/$directory" ]
# assertEquals "Directory Excluded [$TARGET_DIR_FILE_PUSH/$directory]" "1" $?
# done
# Tests presence of rotated files
cd "$OBACKUP_DIR"
./$OBACKUP_EXECUTABLE "$CONF_DIR/$PUSH_CONF"
assertEquals "Return code" "0" $?
for file in "${DatabasePresence[@]}"; do
[ -f "$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file$CRYPT_EXTENSION]" "0" $?
done
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION" ]
assertEquals "File rotated Presence [$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR)$CRYPT_EXTENSION$ROTATE_1_EXTENSION]" "0" $?
2016-09-04 21:26:19 +02:00
_PARANOIA_DEBUG=yes ./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_SQL_PUSH" --passphrase-file="$TESTS_DIR/$PASSFILE" --verbose
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt sql storage in [$TARGET_DIR_SQL_PUSH]" "0" $?
2016-09-02 13:13:53 +02:00
2016-09-02 16:08:23 +02:00
./$OBACKUP_EXECUTABLE --decrypt="$TARGET_DIR_FILE_PUSH" --passphrase-file="$TESTS_DIR/$PASSFILE"
2016-09-02 23:20:48 +02:00
assertEquals "Decrypt file storage in [$TARGET_DIR_FILE_PUSH]" "0" $?
SetEncryption "$CONF_DIR/$PUSH_CONF" false
2016-08-18 14:19:52 +02:00
}
2016-09-02 23:22:29 +02:00
function test_WaitForTaskCompletion () {
2016-08-18 14:19:52 +02:00
# Tests if wait for task completion works correctly
2016-08-18 22:38:28 +02:00
# Standard wait
2016-09-04 08:07:17 +02:00
sleep 1 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 2 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-08-18 22:38:28 +02:00
WaitForTaskCompletion $pids 0 0 ${FUNCNAME[0]} true 0
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 1" "0" $?
2016-08-18 22:38:28 +02:00
# Standard wait with warning
2016-09-04 08:07:17 +02:00
sleep 2 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 5 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-09-04 08:07:17 +02:00
WaitForTaskCompletion $pids 3 0 ${FUNCNAME[0]} true 0
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 2" "0" $?
2016-08-18 22:38:28 +02:00
# Both pids are killed
2016-09-04 08:07:17 +02:00
sleep 5 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 5 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-09-04 08:07:17 +02:00
WaitForTaskCompletion $pids 0 2 ${FUNCNAME[0]} true 0
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 3" "2" $?
2016-08-18 22:38:28 +02:00
# One of two pids are killed
2016-09-04 08:07:17 +02:00
sleep 2 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-08-18 17:10:53 +02:00
sleep 10 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-09-04 08:07:17 +02:00
WaitForTaskCompletion $pids 0 3 ${FUNCNAME[0]} true 0
2016-08-18 14:19:52 +02:00
assertEquals "WaitForTaskCompletion test 4" "1" $?
2016-08-18 22:38:28 +02:00
# Count since script begin, the following should output two warnings and both pids should get killed
2016-09-04 08:07:17 +02:00
sleep 20 &
2016-08-18 22:38:28 +02:00
pids="$!"
2016-09-04 08:07:17 +02:00
sleep 20 &
2016-08-18 22:38:28 +02:00
pids="$pids;$!"
2016-09-04 08:07:17 +02:00
WaitForTaskCompletion $pids 3 5 ${FUNCNAME[0]} false 0
2016-08-18 22:38:28 +02:00
assertEquals "WaitForTaskCompletion test 5" "2" $?
2016-08-18 14:19:52 +02:00
}
2016-09-02 23:22:29 +02:00
function test_ParallelExec () {
2016-08-30 21:50:04 +02:00
# Test if parallelExec works correctly
2016-09-02 13:13:53 +02:00
cmd="sleep 2;sleep 2;sleep 2;sleep 2"
2016-08-30 21:50:04 +02:00
ParallelExec 4 "$cmd"
assertEquals "ParallelExec test 1" "0" $?
2016-09-02 13:13:53 +02:00
cmd="sleep 2;du /none;sleep 2"
2016-08-30 21:50:04 +02:00
ParallelExec 2 "$cmd"
assertEquals "ParallelExec test 2" "1" $?
2016-09-02 13:13:53 +02:00
cmd="sleep 4;du /none;sleep 3;du /none;sleep 2"
2016-08-30 21:50:04 +02:00
ParallelExec 3 "$cmd"
assertEquals "ParallelExec test 3" "2" $?
}
2016-09-09 12:36:30 +02:00
function test_UpgradeConfPullRun () {
# Basic return code tests. Need to go deep into file presence testing
cd "$OBACKUP_DIR"
./$OBACKUP_UPGRADE "$CONF_DIR/$OLD_CONF"
assertEquals "Conf file upgrade" "0" $?
./$OBACKUP_EXECUTABLE "$CONF_DIR/$OLD_CONF"
assertEquals "Upgraded conf file execution test" "0" $?
# Move pre-upgraded file to original location agian
mv -f "$CONF_DIR/$OLD_CONF.save" "$CONF_DIR/$OLD_CONF"
}
2016-08-30 16:12:10 +02:00
. "$TESTS_DIR/shunit2/shunit2"
2016-09-03 14:18:03 +02:00