#!/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"
}
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