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