]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add test for no media in config
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 14:23:44 +0000 (16:23 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 14:23:44 +0000 (16:23 +0200)
src/backupmount
tests/backupmount_tests.bats

index efa733ad3fbca660e845f4264e8144e625470456..fc8c228b6ff43e08fca22e51194ab39851b63458 100755 (executable)
@@ -33,7 +33,13 @@ exists_config_file()
 
 mount_backup()
 {
-       :
+       local config="$1"
+       local media=
+       mapfile -t media < <(echo "$config" \
+               | jq --raw-output ".media | keys[]" 2> /dev/null)
+       [ "${#media[@]}" -gt 0 ] \
+               || errlog "missing media in $CONFIG_FILE" \
+               || return $?
 }
 
 umount_backup()
@@ -59,7 +65,7 @@ main()
                || return $?
 
        case $cmd in
-       "mount") mount_backup || return $? ;;
+       "mount") mount_backup "$config" || return $? ;;
        "umount") umount_backup || return $? ;;
        *) errlog "unknown command" && return 1 ;;
        esac
index 150545eb12818213f895f94fcd2c6bb8261adee2..cd269957ff248219a4733f81fb8e7696334ddefc 100755 (executable)
@@ -101,4 +101,17 @@ teardown() {
        assert_failure
        assert_line --index 0 "⭐ START: backupmount"
        assert_line --index 1 "❌ ERROR: unknown command"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure no media" {
+       yq() {
+               echo '{}'
+       }
+
+       run main "mount"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backupmount"
+       assert_line --index 1 "❌ ERROR: missing media in src/config-example.yaml"
 }
\ No newline at end of file