From 99c3d6d6b1b454f4c9f359e33bbea72393a9ecb8 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Mon, 3 Aug 2026 18:25:15 +0200 Subject: [PATCH] add test config not found --- src/backup | 14 +++++++++++++- tests/backup_tests.bats | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/backup b/src/backup index 09b17e2..a5a1a1f 100755 --- a/src/backup +++ b/src/backup @@ -9,8 +9,18 @@ errlog() return $lastexit } +exists_config_file() +{ + local config_file="$1" + + [ -f "$config_file" ] \ + || errlog "file $config_file not found" \ + || return $? +} + main() { + local CONFIG_FILE=${CONFIG_FILE:="config.yaml"} echo "⭐ START: backup" command -v yq > /dev/null \ @@ -25,7 +35,9 @@ main() command -v ssh > /dev/null \ || errlog "command ssh not found" \ || return $? + exists_config_file "$CONFIG_FILE" \ + || return $? } -[ "$TESTMODE" == "ON" ] || return 0 +[ "$TESTMODE" == "ON" ] && return 0 main "$@" \ No newline at end of file diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 6bc8716..b724650 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -3,8 +3,11 @@ setup() { bats_load_library 'bats-support' bats_load_library 'bats-assert' - export TESTMODE=ON + export TESTMODE="ON" source src/backup + exists_config_file() { + return 0 + } } teardown() { @@ -71,3 +74,15 @@ teardown() { assert_line --index 0 "⭐ START: backup" assert_line --index 1 "❌ ERROR: command ssh not found" } + +@test "failure config.yaml not found" { + exists_config_file() { + errlog "file config.yaml not found" + return 1 + } + + run main + + assert_line --index 0 "⭐ START: backup" + assert_line --index 1 "❌ ERROR: file config.yaml not found" +} -- 2.47.3