]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add check exists commands
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 13:30:31 +0000 (15:30 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 13:30:31 +0000 (15:30 +0200)
src/backupmount
tests/backupmount_tests.bats

index 9b35334c4e578ddfa3d993c4d6274cfe72de3256..20f31d4a0746835352ec324230120261e0d71553 100755 (executable)
@@ -1,7 +1,31 @@
 #!/bin/bash
 
+errlog()
+{
+       local lastexit=$?
+       local msg="$1"
+
+       echo "❌ ERROR: $msg"
+       return $lastexit
+}
+
+exists_needed_commands()
+{
+       command -v yq > /dev/null \
+               || errlog "command yq not found" \
+               || return $?
+       command -v jq > /dev/null \
+               || errlog "command jq not found" \
+               || return $?
+       command -v cryptsetup > /dev/null \
+               || errlog "command cryptsetup not found" \
+               || return $?
+}
+
 main()
 {
+       local CONFIG_FILE=${CONFIG_FILE:="config.yaml"}
+       exists_needed_commands || return $?
        echo "⭐ START: backupmount"
 }
 
index 16f11c76733fb17a20ae83b8f31882ec704f8bdb..786aad52abf5fd0566db9dbdcdb3ed8877a73bc9 100755 (executable)
@@ -14,8 +14,48 @@ teardown() {
        unset CONFIG_FILE
 }
 
+# bats test_tags=backupmount:start
 @test "success start backupmount" {
+       exists_needed_commands() {
+               return 0
+       }
        run main
 
        assert_line --index 0 "⭐ START: backupmount"
+}
+
+# bats test_tags=backupmount:start,backupmount:cmd
+@test "failure yq command not found" {
+       command() {
+               return 1
+       }
+
+       run main
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command yq not found"
+}
+
+# bats test_tags=backupmount:start,backupmount:cmd
+@test "failure jq command not found" {
+       command() {
+               [ "$2" != "jq" ] || return 1
+       }
+
+       run main
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command jq not found"
+}
+
+# bats test_tags=backupmount:start,backupmount:cmd
+@test "failure cryptsetup command not found" {
+       command() {
+               [ "$2" != "cryptsetup" ] || return 1
+       }
+
+       run main
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command cryptsetup not found"
 }
\ No newline at end of file