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

index ef2db5b93c0e978f1f7e95a820089a5f33a0f833..a1d0ba516915a7c3d975b80144f542f159669a2b 100755 (executable)
@@ -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()
index 5610b99895524f6bc0963bf42088d02532de737b..2fc3524728a70952e9caeaa96100158bccf9c705 100755 (executable)
@@ -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