]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add tests for needed commands
authorBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 07:43:54 +0000 (09:43 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 07:43:54 +0000 (09:43 +0200)
src/restore
tests/restore_tests.bats

index 8df979b0aeb1357e493188484a10a52e98d49c15..c1856345e274e84826e35293e0c11412de20dcc9 100755 (executable)
@@ -1,7 +1,33 @@
 #!/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 rsync > /dev/null \
+               || errlog "command rsync not found" \
+               || return $?
+       command -v ssh > /dev/null \
+               || errlog "command ssh not found" \
+               || return $?
+}
+
 main()
 {
+       exists_needed_commands || return $?
        echo "⭐ START: restore"
 }
 
index c4565aa93130cdeed3914b0ab6d1c1cdbea86e63..72e3e33df9f5f6b18faeb8ad27c1cd55cec00514 100755 (executable)
@@ -35,4 +35,52 @@ teardown() {
 
        assert_success
        assert_line --index 0 "⭐ START: restore"
+}
+
+# bats test_tags=backup:start,backup: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=backup:start,backup: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=backup:start,backup:cmd
+@test "failure rsync command not found" {
+       command() {
+               [ "$2" != "rsync" ] || return 1
+       }
+
+       run main
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command rsync not found"
+}
+
+# bats test_tags=backup:start,backup:cmd
+@test "failure ssh command not found" {
+       command() {
+               [ "$2" != "ssh" ] || return 1
+       }
+
+       run main
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command ssh not found"
 }
\ No newline at end of file