|| 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"
export TESTMODE="ON"
export CONFIG_FILE="src/config-example.yaml"
source src/backupmount
+ command() {
+ return 0
+ }
}
teardown() {
# bats test_tags=backupmount:start
@test "success start backupmount" {
- exists_needed_commands() {
- return 0
- }
-
run main
assert_line --index 0 "⭐ START: backupmount"
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"