From: Bastian Dehn Date: Sun, 16 Aug 2026 14:07:20 +0000 (+0200) Subject: add config check exists X-Git-Tag: v1.0.7^2~1^2~24 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=782c2f1575577f395511f3b44f1471e7baabdf4b;p=simple-backup.git add config check exists --- diff --git a/src/backupmount b/src/backupmount index f68157f..7eaeebb 100755 --- a/src/backupmount +++ b/src/backupmount @@ -22,10 +22,25 @@ exists_needed_commands() || return $? } +exists_config_file() +{ + local config_file="$1" + + [ -f "$config_file" ] \ + || errlog "file $config_file not found" \ + || return $? +} + main() { + local config= local CONFIG_FILE=${CONFIG_FILE:="config.yaml"} exists_needed_commands || return $? + exists_config_file "$CONFIG_FILE" || return $? + config=$(yq '.' "$CONFIG_FILE") \ + || errlog "failed to load $CONFIG_FILE" \ + || return $? + echo "⭐ START: backupmount" local cmd="$1" diff --git a/tests/backupmount_tests.bats b/tests/backupmount_tests.bats index dc164fd..6000681 100755 --- a/tests/backupmount_tests.bats +++ b/tests/backupmount_tests.bats @@ -6,6 +6,9 @@ setup() { export TESTMODE="ON" export CONFIG_FILE="src/config-example.yaml" source src/backupmount + command() { + return 0 + } } teardown() { @@ -16,10 +19,6 @@ teardown() { # bats test_tags=backupmount:start @test "success start backupmount" { - exists_needed_commands() { - return 0 - } - run main assert_line --index 0 "⭐ START: backupmount" @@ -61,14 +60,35 @@ teardown() { assert_line --index 0 "❌ ERROR: command cryptsetup not found" } -# bats test_tags=backupmount:start -@test "failure missing command parameter" { - exists_needed_commands() { - return 0 +# bats test_tags=backupmount:config +@test "failure config.yaml not found" { + exists_config_file() { + errlog "file config.yaml not found" + return 1 } run main + assert_failure + assert_line --index 0 "❌ ERROR: file config.yaml not found" +} + +# bats test_tags=backupmount:config +@test "failure load config.yaml" { + yq() { + return 1 + } + + run main + + assert_failure + assert_line --index 0 "❌ ERROR: failed to load src/config-example.yaml" +} + +# bats test_tags=backupmount:start +@test "failure missing command parameter" { + run main + assert_failure assert_line --index 0 "⭐ START: backupmount" assert_line --index 1 "❌ ERROR: missing command"