1
0
mirror of https://github.com/deajan/obackup.git synced 2024-11-14 11:43:41 +01:00
obackup/dev/tests/run_local_tests.sh

303 lines
8.1 KiB
Bash
Raw Normal View History

2016-08-18 14:19:52 +02:00
#!/usr/bin/env bash
2016-08-30 19:17:14 +02:00
## obackup test suite 2016083003
2016-08-30 16:12:10 +02:00
# Stupid and very basic tests v0.0000003-alpha-dev-pre-everything
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-08-18 14:19:52 +02:00
2016-08-30 18:12:59 +02:00
OBACKUP_EXECUTABLE=obackup.sh
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-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-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
function oneTimeSetUp () {
source "$DEV_DIR/ofunctions.sh"
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"
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"
"$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-08-18 17:10:53 +02:00
if [ "$IS_STABLE" == "no" ]; then
2016-08-30 18:12:59 +02:00
sed -i 's/^IS_STABLE=yes/IS_STABLE=no/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
2016-08-18 17:10:53 +02:00
fi
2016-08-18 14:19:52 +02:00
2016-08-18 17:10:53 +02:00
#rm -rf $SOURCE_DIR
#rm -rf $TARGET_DIR
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-08-18 17:10:53 +02:00
2016-08-30 18:12:59 +02:00
function test_SetStable () {
if grep "^IS_STABLE=YES" "$OBACKUP_DIR/$OBACKUP_EXECUTABLE" > /dev/null; then
IS_STABLE=yes
else
IS_STABLE=no
sed -i 's/^IS_STABLE=no/IS_STABLE=yes/' "$OBACKUP_DIR/$OBACKUP_EXECUTABLE"
assertEquals "Set as stable" "0" $?
fi
}
2016-08-18 14:19:52 +02:00
function test_FirstLocalRun () {
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-08-30 18:12:59 +02:00
./$OBACKUP_EXECUTABLE dev/tests/conf/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
}
function test_SecondLocalRun () {
# Only tests presence of rotated files
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-08-30 18:12:59 +02:00
./$OBACKUP_EXECUTABLE dev/tests/conf/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
[ -f "$TARGET_DIR_SQL_LOCAL/$file.obackup.1" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_LOCAL/$file]" "0" $?
done
2016-08-18 14:19:52 +02:00
[ -d "$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR).obackup.1" ]
2016-08-30 19:17:14 +02:00
assertEquals "File rotated Presence [$TARGET_DIR_FILE_LOCAL/$(dirname $SOURCE_DIR).obackup.1]" "0" $?
2016-08-18 14:19:52 +02:00
}
2016-08-30 19:17:14 +02:00
2016-08-18 14:19:52 +02:00
function test_FirstPullRun () {
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-08-30 18:12:59 +02:00
./$OBACKUP_EXECUTABLE dev/tests/conf/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
}
function test_SecondPullRun () {
# Only tests presence of rotated files
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-08-30 18:12:59 +02:00
./$OBACKUP_EXECUTABLE dev/tests/conf/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
[ -f "$TARGET_DIR_SQL_PULL/$file.obackup.1" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PULL/$file]" "0" $?
done
2016-08-18 14:19:52 +02:00
[ -d "$TARGET_DIR_FILE_PULL/$(dirname $SOURCE_DIR).obackup.1" ]
2016-08-18 17:10:53 +02:00
assertEquals "File rotated Presence" "0" $?
2016-08-18 14:19:52 +02:00
}
function test_FirstPushRun () {
# Basic return code tests. Need to go deep into file presence testing
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-08-30 18:12:59 +02:00
./$OBACKUP_EXECUTABLE dev/tests/conf/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
}
function test_SecondPushRun () {
# Only tests presence of rotated files
2016-08-30 16:26:30 +02:00
cd "$OBACKUP_DIR"
2016-08-30 18:12:59 +02:00
./$OBACKUP_EXECUTABLE dev/tests/conf/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
[ -f "$TARGET_DIR_SQL_PUSH/$file.obackup.1" ]
assertEquals "Database rotated Presence [$TARGET_DIR_SQL_PUSH/$file]" "0" $?
done
2016-08-18 14:19:52 +02:00
[ -d "$TARGET_DIR_FILE_PUSH/$(dirname $SOURCE_DIR).obackup.1" ]
2016-08-18 17:10:53 +02:00
assertEquals "File rotated Presence" "0" $?
2016-08-18 14:19:52 +02:00
}
function test_WaitForTaskCompletion () {
# Tests if wait for task completion works correctly
2016-08-18 22:38:28 +02:00
# Standard wait
2016-08-18 17:10:53 +02:00
sleep 3 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-08-18 17:10:53 +02:00
sleep 5 &
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-08-18 17:10:53 +02:00
sleep 5 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-08-18 17:10:53 +02:00
sleep 8 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-08-18 22:38:28 +02:00
WaitForTaskCompletion $pids 6 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-08-18 17:10:53 +02:00
sleep 7 &
2016-08-18 14:19:52 +02:00
pids="$!"
2016-08-18 17:10:53 +02:00
sleep 9 &
2016-08-18 14:19:52 +02:00
pids="$pids;$!"
2016-08-18 22:38:28 +02:00
WaitForTaskCompletion $pids 0 5 ${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-08-18 17:10:53 +02:00
sleep 3 &
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-08-18 22:38:28 +02:00
WaitForTaskCompletion $pids 0 7 ${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
sleep 5 &
pids="$!"
sleep 10 &
pids="$pids;$!"
WaitForTaskCompletion $pids 8 15 ${FUNCNAME[0]} false 0
assertEquals "WaitForTaskCompletion test 5" "2" $?
2016-08-18 14:19:52 +02:00
}
2016-08-30 16:12:10 +02:00
. "$TESTS_DIR/shunit2/shunit2"