]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add config check exists
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 14:07:20 +0000 (16:07 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 14:07:38 +0000 (16:07 +0200)
src/backupmount
tests/backupmount_tests.bats

index f68157fd7adefa4495cf3556b0e9f21a8ef5432c..7eaeebbd515b9d6c07bdbeada95d9e6ac57fd711 100755 (executable)
@@ -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"
index dc164fd3c550b394ff875a9219bdab2a74752927..600068146f6bd68d8e869d157a0421b58071a509 100755 (executable)
@@ -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"