From: Bastian Dehn Date: Sun, 16 Aug 2026 15:10:23 +0000 (+0200) Subject: add test for key not exists X-Git-Tag: v1.0.7^2~1^2~18 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=8709d3fb8fa0baee98b955a6ac6ef2e8eefd3c82;p=simple-backup.git add test for key not exists --- diff --git a/src/backupmount b/src/backupmount index ef2db5b..a1d0ba5 100755 --- a/src/backupmount +++ b/src/backupmount @@ -41,6 +41,16 @@ exists_block_device() || return $? } +exists_key() +{ + local media="$1" + local key="$2" + + [ -f "$key" ] \ + || errlog "key $key for media $media not exists" \ + || return $? +} + mount_device() { local config="$1" @@ -60,6 +70,7 @@ mount_device() [ "$key" != "null" ] \ || errlog "missing key for media $media in $CONFIG_FILE" \ || return $? + exists_key "$media" "$key" || return $? } mount_backup() diff --git a/tests/backupmount_tests.bats b/tests/backupmount_tests.bats index 5610b99..2fc3524 100755 --- a/tests/backupmount_tests.bats +++ b/tests/backupmount_tests.bats @@ -165,4 +165,27 @@ teardown() { assert_failure assert_line --index 0 "⭐ START: backupmount" assert_line --index 1 "❌ ERROR: missing key for media day in src/config-example.yaml" +} + +# bats test_tags=backupmount:mount +@test "failure key not exists for media day" { + yq() { + echo '{ + "media": { + "day": { + "device": "/dev/path/to/day", + "key": "notexistskey" + } + } + }' + } + exists_block_device() { + return 0 + } + + run main "mount" + + assert_failure + assert_line --index 0 "⭐ START: backupmount" + assert_line --index 1 "❌ ERROR: key notexistskey for media day not exists" } \ No newline at end of file