]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add missing key test
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 15:05:08 +0000 (17:05 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 15:05:08 +0000 (17:05 +0200)
src/backupmount
tests/backupmount_tests.bats

index 65c257f63b3874e21073a22a432a7706f8233750..ef2db5b93c0e978f1f7e95a820089a5f33a0f833 100755 (executable)
@@ -45,13 +45,21 @@ mount_device()
 {
        local config="$1"
        local media="$2"
+       local device=
+       local key=
 
        device=$(echo "$config" \
-               | jq --raw-output ".media.\"$one_media\".device")
+               | jq --raw-output ".media.\"$media\".device")
        [ "$device" != "null" ] \
-               || errlog "missing device for media $one_media in $CONFIG_FILE" \
+               || errlog "missing device for media $media in $CONFIG_FILE" \
                || return $?
        exists_block_device "$media" "$device" || return $?
+
+       key=$(echo "$config" \
+               | jq --raw-output ".media.\"$media\".key")
+       [ "$key" != "null" ] \
+               || errlog "missing key for media $media in $CONFIG_FILE" \
+               || return $?
 }
 
 mount_backup()
index f809780bb18d982d63f821f09511fcbf8ad1e711..5610b99895524f6bc0963bf42088d02532de737b 100755 (executable)
@@ -104,7 +104,7 @@ teardown() {
 }
 
 # bats test_tags=backupmount:mount
-@test "failure no media" {
+@test "failure missing media" {
        yq() {
                echo '{}'
        }
@@ -117,7 +117,7 @@ teardown() {
 }
 
 # bats test_tags=backupmount:mount
-@test "failure no device for media day" {
+@test "failure missing device for media day" {
        yq() {
                echo '{
                        "media": {
@@ -143,4 +143,26 @@ teardown() {
        assert_line --index 2 "❌ ERROR: block device /dev/path/to/week for week not found"
        assert_line --index 3 "❌ ERROR: block device /dev/path/to/month for month not found"
        assert_line --index 4 "❌ ERROR: no device found"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure missing key for media day" {
+       yq() {
+               echo '{
+                       "media": {
+                               "day": {
+                                       "device": "/dev/path/to/day"
+                               }
+                       }
+               }'
+       }
+       exists_block_device() {
+               return 0
+       }
+
+       run main "mount"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backupmount"
+       assert_line --index 1 "❌ ERROR: missing key for media day in src/config-example.yaml"
 }
\ No newline at end of file