From: Bastian Dehn Date: Mon, 17 Aug 2026 14:57:00 +0000 (+0200) Subject: add test check machine entry X-Git-Tag: v1.0.8^2~3 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=84f44dc33416a5032981ef4ddecde1668f39137c;p=simple-backup.git add test check machine entry --- diff --git a/src/restore b/src/restore index c9397cb..f47938f 100755 --- a/src/restore +++ b/src/restore @@ -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" ] \ diff --git a/tests/restore_tests.bats b/tests/restore_tests.bats index 968dffb..68c288f 100755 --- a/tests/restore_tests.bats +++ b/tests/restore_tests.bats @@ -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() {