]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
change rsync parameter tests
authorBastian Dehn <hhaalo@arcor.de>
Thu, 6 Aug 2026 15:38:12 +0000 (17:38 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 6 Aug 2026 15:38:12 +0000 (17:38 +0200)
src/config-example.yaml
tests/backup_tests.bats

index 4d340d307b41d709933441d0814ed6b36e216651..030d19735f05db1ce2ab12248e3f97c1a42feb3d 100644 (file)
@@ -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
 
index 531f31d13411c2b46df6420700b93eff643ad46c..eb5903d0ddceb9d31823d706386793f30b744d47 100755 (executable)
@@ -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