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

index 17dd90f2587fecd7b9bc74ccef4aa59f1dfb0093..2a275f250fa608d186641729c4c101525ff9062c 100755 (executable)
@@ -33,22 +33,20 @@ exists_config_file()
 
 exists_block_device()
 {
-       local media="$1"
-       local device="$2"
+       local device="$1"
+       [ -b "$device" ] || return $?
+}
 
-       [ -b "$device" ] \
-               || errlog "block device $device for $media not found" \
-               || return $?
+exists_partition()
+{
+       local partition="$1"
+       [ -b "$partition" ] || return $?
 }
 
 exists_key()
 {
-       local media="$1"
        local key="$2"
-
-       [ -f "$key" ] \
-               || errlog "key $key for media $media not exists" \
-               || return $?
+       [ -f "$key" ] || return $?
 }
 
 mount_partition()
@@ -72,7 +70,9 @@ mount_device()
        [ "$device" != "null" ] \
                || errlog "missing device for media $media in $CONFIG_FILE" \
                || return $?
-       exists_block_device "$media" "$device" || return $?
+       exists_block_device "$device" \
+               || errlog "block device $device for $media not found" \
+               || return $?
        echo "ℹ️ INFO: media $media with device $device found"
 
        key=$(echo "$config" \
@@ -80,7 +80,9 @@ mount_device()
        [ "$key" != "null" ] \
                || errlog "missing key for media $media in $CONFIG_FILE" \
                || return $?
-       exists_key "$media" "$key" || return $?
+       exists_key "$key" \
+               || errlog "key $key for media $media not exists" \
+               || return $?
        echo "ℹ️ INFO: use key $key"
 
        volume=$(echo "$config" \
@@ -109,6 +111,9 @@ mount_device()
                || errlog "could not open $device with $key" \
                || return $?
 
+       exists_partition "$partition" \
+               || errlog "partition $partition not found" \
+               || return $?
        mount_partition "$partition" "$backup_path" || return $?
 }
 
index c00578a50debf9b514cef19d04e57e74c425a701..610691372e2bd0ae460be9535b87aa25f57fb709 100755 (executable)
@@ -296,6 +296,9 @@ teardown() {
        exists_key() {
                return 0
        }
+       exists_partition() {
+               return 0
+       }
 
        run main "mount"
 
@@ -331,4 +334,29 @@ teardown() {
        assert_line --index 2 "ℹ️ INFO: use key /path/to/luks-key-file-day"
        assert_line --index 3 "ℹ️ INFO: volume open luks-crypt-volume"
        assert_line --index 4 "❌ ERROR: could not open /dev/path/to/day with /path/to/luks-key-file-day"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure mount partition not exists" {
+       exists_block_device() {
+               return 0
+       }
+       exists_key() {
+               return 0
+       }
+       cryptsetup() {
+               return 0
+       }
+       exists_partition() {
+               return 1
+       }
+
+       run main "mount"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backupmount"
+       assert_line --index 1 "ℹ️ INFO: media day with device /dev/path/to/day found"
+       assert_line --index 2 "ℹ️ INFO: use key /path/to/luks-key-file-day"
+       assert_line --index 3 "ℹ️ INFO: volume open luks-crypt-volume"
+       assert_line --index 4 "❌ ERROR: partition /dev/path/to/partday not found"
 }
\ No newline at end of file