]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add test for missing remote user
authorBastian Dehn <hhaalo@arcor.de>
Wed, 5 Aug 2026 18:48:43 +0000 (20:48 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 5 Aug 2026 18:48:43 +0000 (20:48 +0200)
src/backup
tests/backup_tests.bats

index 6a501ff6444046163e4b9b465e3cec532a9de7ba..0a5d574d398fedd91d4f5d346bc33eac0ea7fd97 100755 (executable)
@@ -134,7 +134,13 @@ path_backup()
        local machine="$2"
        local path="$3"
        local full_backup_path="$4"
+       local remote_user=
 
+       remote_user=$(echo "$config" \
+               | jq --raw-output ".machines.$machine.remote_user")
+       [ "$remote_user" != "null" ] \
+               || errlog "no remote user for $machine" \
+               || return $?
        # TODO: config read - rsync implementation
 }
 
index 2f3ecd94d2dacde96e615d09e952c6217bca725e..49c6082370bf37d6a609857a00ff8cdd7ccfca99 100755 (executable)
@@ -334,4 +334,33 @@ teardown() {
        assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
        assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1"
        assert_line --index 7 "❌ ERROR: missing pathes for machine testpc1"
+}
+
+@test "failure backup machine path no remote user" {
+       yq() {
+               echo '{
+                       "backup_path": "build",
+                       "backup_name": "backup",
+                       "backup_count": 15,
+                       "machines": {
+                               "testpc1": {
+                                       "pathes": ["/home/user"]
+                               }
+                       }
+                       }'
+       }
+
+       run main
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backup"
+       assert_line --index 1 "ℹ️ INFO: backup path build"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "ℹ️ INFO: backup count 15"
+       assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
+       assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
+       assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1"
+       assert_line --index 7 "################################################################################"
+       assert_line --index 8 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc1${RESET}; path ${YELLOW}/home/user${RESET}"
+       assert_line --index 9 "❌ ERROR: no remote user for testpc1"
 }
\ No newline at end of file