From ee8ae39b531b5fc25ba52d1e72079df8f955bbc9 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 16 Aug 2026 19:14:10 +0200 Subject: [PATCH] add test for checking exists partition block device --- src/backupmount | 29 +++++++++++++++++------------ tests/backupmount_tests.bats | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/backupmount b/src/backupmount index 17dd90f..2a275f2 100755 --- a/src/backupmount +++ b/src/backupmount @@ -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 $? } diff --git a/tests/backupmount_tests.bats b/tests/backupmount_tests.bats index c00578a..6106913 100755 --- a/tests/backupmount_tests.bats +++ b/tests/backupmount_tests.bats @@ -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 -- 2.47.3