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

index c1c02371ce1105b4a48dec687c18ccf2c5b55edc..aa53b92ec9498325e0598600f0d769b8fe61923a 100755 (executable)
@@ -140,12 +140,17 @@ path_backup()
        remote_user=$(echo "$config" \
                | jq --raw-output ".machines.$machine.remote_user")
        [ "$remote_user" != "null" ] \
-               || errlog "no remote user for $machine" \
+               || errlog "missing remote user for $machine" \
                || return $?
        host=$(echo "$config" \
                | jq --raw-output ".machines.$machine.host")
        [ "$host" != "null" ] \
-               || errlog "no host for $machine" \
+               || errlog "missing host for $machine" \
+               || return $?
+       port=$(echo "$config" \
+               | jq --raw-output ".machines.$machine.port")
+       [ "$port" != "null" ] \
+               || errlog "missing port for $machine" \
                || return $?
        # TODO: config read - rsync implementation
 }
index ce2ed1c4ea45ef9736e965b80ebca946f2c56581..af9d21eb34604d005353be6e2d59b7c68d46eaa6 100755 (executable)
@@ -362,7 +362,7 @@ teardown() {
        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"
+       assert_line --index 9 "❌ ERROR: missing remote user for testpc1"
 }
 
 @test "failure backup machine path no host" {
@@ -392,5 +392,36 @@ teardown() {
        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 host for testpc1"
+       assert_line --index 9 "❌ ERROR: missing host for testpc1"
+}
+
+@test "failure backup machine path no port" {
+       yq() {
+               echo '{
+                       "backup_path": "build",
+                       "backup_name": "backup",
+                       "backup_count": 15,
+                       "machines": {
+                               "testpc1": {
+                                       "remote_user": "testuser",
+                                       "host": "remotehost",
+                                       "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: missing port for testpc1"
 }
\ No newline at end of file