From: Bastian Dehn Date: Thu, 6 Aug 2026 15:38:12 +0000 (+0200) Subject: change rsync parameter tests X-Git-Tag: v1.0.6^2~1^2~42 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=0a782173447ec4a3517449f9997c58130d11320f;p=simple-backup.git change rsync parameter tests --- diff --git a/src/config-example.yaml b/src/config-example.yaml index 4d340d3..030d197 100644 --- a/src/config-example.yaml +++ b/src/config-example.yaml @@ -18,10 +18,6 @@ machines: remote_user: backupuser host: www.example.com port: 22 - # excludes optional - excludes: - - /home/user/.cache - - /home/user/.local pathes: - /home/other diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 531f31d..eb5903d 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -6,20 +6,31 @@ setup() { 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" { @@ -483,49 +494,45 @@ teardown() { } @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