]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add test check machine entry
authorBastian Dehn <hhaalo@arcor.de>
Mon, 17 Aug 2026 14:57:00 +0000 (16:57 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 17 Aug 2026 17:31:13 +0000 (19:31 +0200)
src/restore
tests/restore_tests.bats

index c9397cb3a2f549bf468a91389e8772e631dcf35b..f47938fff4fdcd51c9724fa1f2d39df9dc94bef9 100755 (executable)
@@ -53,7 +53,7 @@ exists_backup_path()
        local backup_path=
        backup_path=$(echo "$config" | jq --raw-output '.backup_path')
        [ "$backup_path" != "null" ] \
-               || errlog "$CONFIG_FILE missing backup_path" \
+               || errlog "missing backup_path in $CONFIG_FILE" \
                || return $?
        echo "ℹ️ INFO: backup path $backup_path"
 }
@@ -64,7 +64,7 @@ exists_backup_name()
        local backup_name=
        backup_name=$(echo "$config" | jq --raw-output '.backup_name')
        [ "$backup_name" != "null" ] \
-               || errlog "$CONFIG_FILE missing backup_name" \
+               || errlog "missing backup_name in $CONFIG_FILE" \
                || return $?
        echo "ℹ️ INFO: backup name $backup_name"
 }
@@ -105,6 +105,10 @@ restore()
                | jq --raw-output ".backup_path")
        backup_name=$(echo "$config" \
                | jq --raw-output ".backup_name")
+       echo "$config" \
+               | jq --exit-status ".machines | has(\"$machine\")" > /dev/null \
+               || errlog "missing machine $machine in $CONFIG_FILE" \
+               || return $?
        remote_user=$(echo "$config" \
                | jq --raw-output ".machines.\"$machine\".remote_user")
        [ "$remote_user" != "null" ] \
index 968dffb9ec2425fb7a1f14b62a213a26dad8216b..68c288f53b1c1765dae67508ea2b9f6bbd046290 100755 (executable)
@@ -113,7 +113,7 @@ teardown() {
 
        assert_failure
        assert_line --index 0 "⭐ START: restore"
-       assert_line --index 1 "❌ ERROR: src/config-example.yaml missing backup_path"
+       assert_line --index 1 "❌ ERROR: missing backup_path in src/config-example.yaml"
 }
 
 # bats test_tags=restore:start,restore:config
@@ -127,7 +127,7 @@ teardown() {
        assert_failure
        assert_line --index 0 "⭐ START: restore"
        assert_line --index 1 "ℹ️ INFO: backup path path"
-       assert_line --index 2 "❌ ERROR: src/config-example.yaml missing backup_name"
+       assert_line --index 2 "❌ ERROR: missing backup_name in src/config-example.yaml"
 }
 
 # bats test_tags=restore:start,restore:config
@@ -203,6 +203,27 @@ teardown() {
        assert_line --index 3 "❌ ERROR: missing path (-p)"
 }
 
+# bats test_tags=restore:config
+@test "failure config missing machine" {
+       yq() {
+               echo '{
+                       "backup_path": "build/test",
+                       "backup_name": "backup",
+                       "machines": {
+                               "testpc2.example.com": {}
+                       }
+               }'
+       }
+
+       run main -d "2000-01-01" -n "01" -r "testpc1.example.com" -p "/testpath"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: restore"
+       assert_line --index 1 "ℹ️ INFO: backup path build/test"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "❌ ERROR: missing machine testpc1.example.com in src/config-example.yaml"
+}
+
 # bats test_tags=restore:config
 @test "failure config missing remote user" {
        yq() {