export TESTMODE="ON"
export NOCOLOR="ON"
export CONFIG_FILE="src/config-example.yaml"
+ export RSYNC_LOG="build/rsync.log"
+ export RSYNC_LOG_RUNS="0"
source src/backup
date() {
echo "2000-01-01"
}
rsync() {
- :
+ [ "$RSYNC_LOG_RUNS" -eq "0" ] && return 0
+ ((RSYNC_LOG_RUNS--))
+ [ "$RSYNC_LOG_RUNS" -eq "0" ] || return 0
+
+ echo "${#@}" > "$RSYNC_LOG"
+ for i in $(seq 1 "${#@}"); do
+ echo "${@:i:1}" >> "$RSYNC_LOG"
+ done
}
}
teardown() {
+ rm --recursive --force "build/2000-01-01_01_backup"
+ rm --recursive --force "$RSYNC_LOG"
unset TESTMODE
unset NOCOLOR
unset CONFIG_FILE
- rm --recursive --force "build/2000-01-01_01_backup"
+ unset RSYNC_LOG
}
@test "backup run success" {
}
@test "success backup machine path rsync parameters" {
- local runonce="0"
- rsync() {
- [ "$runonce" == "1" ] && return 0
- [ "$1" == "--archive" ]; shift
- [ "$1" == "--verbose" ]; shift
- [ "$1" == "--sparse" ]; shift
- [ "$1" == "--acls" ]; shift
- [ "$1" == "--hard-links" ]; shift
- [ "$1" == "--relative" ]; shift
- [ "$1" == "--human-readable" ]; shift
- [ "$1" == "--exclude=\"/home/user/.cache\"" ]; shift
- [ "$1" == "--exclude=\"/home/user/.local\"" ]; shift
- [ "$1" == "--rsh=\"ssh -p 22\"" ]; shift
- [ "$1" == "backupuser@www.example.com:/etc" ]; shift
- [ "$1" == "build/2000-01-01_01_backup/testpc1" ]
- runonce="1"
- }
+ RSYNC_LOG_RUNS="1"
+
run main
assert_success
assert_line --index 0 "⭐ START: backup"
assert_line --partial "✅ SUCCESS: backup"
+ assert_equal "$(awk 'NR==1 {print; exit}' "$RSYNC_LOG")" "12"
+ assert_equal "$(awk 'NR==2 {print; exit}' "$RSYNC_LOG")" "--archive"
+ assert_equal "$(awk 'NR==3 {print; exit}' "$RSYNC_LOG")" "--verbose"
+ assert_equal "$(awk 'NR==4 {print; exit}' "$RSYNC_LOG")" "--sparse"
+ assert_equal "$(awk 'NR==5 {print; exit}' "$RSYNC_LOG")" "--acls"
+ assert_equal "$(awk 'NR==6 {print; exit}' "$RSYNC_LOG")" "--hard-links"
+ assert_equal "$(awk 'NR==7 {print; exit}' "$RSYNC_LOG")" "--relative"
+ assert_equal "$(awk 'NR==8 {print; exit}' "$RSYNC_LOG")" "--human-readable"
+ assert_equal "$(awk 'NR==9 {print; exit}' "$RSYNC_LOG")" "--exclude=\"/home/user/.cache\""
+ assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "--exclude=\"/home/user/.local\""
+ assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "--rsh=\"ssh -p 22\""
+ assert_equal "$(awk 'NR==12 {print; exit}' "$RSYNC_LOG")" "backupuser@www.example.com:/etc"
+ assert_equal "$(awk 'NR==13 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/testpc1"
+
}
@test "success backup machine path rsync parameters without excludes" {
- local runonce="0"
- rsync() {
- [ "$runonce" == "1" ] && return 0
- [ "$1" == "--archive" ]; shift
- [ "$1" == "--verbose" ]; shift
- [ "$1" == "--sparse" ]; shift
- [ "$1" == "--acls" ]; shift
- [ "$1" == "--hard-links" ]; shift
- [ "$1" == "--relative" ]; shift
- [ "$1" == "--human-readable" ]; shift
- [ "$1" == "--rsh=\"ssh -p 22\"" ]; shift
- [ "$1" == "backupuser@www.example.com:/etc" ]; shift
- [ "$1" == "build/2000-01-01_01_backup/testpc1" ]
- runonce="1"
- }
+ RSYNC_LOG_RUNS="3"
run main
assert_success
assert_line --index 0 "⭐ START: backup"
assert_line --partial "✅ SUCCESS: backup"
+ assert_equal "$(awk 'NR==1 {print; exit}' "$RSYNC_LOG")" "10"
+ assert_equal "$(awk 'NR==2 {print; exit}' "$RSYNC_LOG")" "--archive"
+ assert_equal "$(awk 'NR==3 {print; exit}' "$RSYNC_LOG")" "--verbose"
+ assert_equal "$(awk 'NR==4 {print; exit}' "$RSYNC_LOG")" "--sparse"
+ assert_equal "$(awk 'NR==5 {print; exit}' "$RSYNC_LOG")" "--acls"
+ assert_equal "$(awk 'NR==6 {print; exit}' "$RSYNC_LOG")" "--hard-links"
+ assert_equal "$(awk 'NR==7 {print; exit}' "$RSYNC_LOG")" "--relative"
+ assert_equal "$(awk 'NR==8 {print; exit}' "$RSYNC_LOG")" "--human-readable"
+ assert_equal "$(awk 'NR==9 {print; exit}' "$RSYNC_LOG")" "--rsh=\"ssh -p 22\""
+ assert_equal "$(awk 'NR==10 {print; exit}' "$RSYNC_LOG")" "backupuser@www.example.com:/home/other"
+ assert_equal "$(awk 'NR==11 {print; exit}' "$RSYNC_LOG")" "build/2000-01-01_01_backup/testpc2"
}
\ No newline at end of file