]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add test config not found
authorBastian Dehn <hhaalo@arcor.de>
Mon, 3 Aug 2026 16:25:15 +0000 (18:25 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 3 Aug 2026 16:25:15 +0000 (18:25 +0200)
src/backup
tests/backup_tests.bats

index 09b17e29adab2e14fc6bacae94bf00290db00a59..a5a1a1f5e6a69243c12cc01afb15864f3bd0a2cb 100755 (executable)
@@ -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
index 6bc87162c39ebb2ee16679c18e30c199a666b1cf..b724650d7bbc920465530a884ff1dc2eb12c00d3 100755 (executable)
@@ -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"
+}