From 42987784ab2334f55bfb977e23923c841931ae10 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 16 Aug 2026 17:05:08 +0200 Subject: [PATCH] add missing key test --- src/backupmount | 12 ++++++++++-- tests/backupmount_tests.bats | 26 ++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/backupmount b/src/backupmount index 65c257f..ef2db5b 100755 --- a/src/backupmount +++ b/src/backupmount @@ -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() diff --git a/tests/backupmount_tests.bats b/tests/backupmount_tests.bats index f809780..5610b99 100755 --- a/tests/backupmount_tests.bats +++ b/tests/backupmount_tests.bats @@ -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 -- 2.47.3