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()
[ "$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" \
[ "$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" \
|| errlog "could not open $device with $key" \
|| return $?
+ exists_partition "$partition" \
+ || errlog "partition $partition not found" \
+ || return $?
mount_partition "$partition" "$backup_path" || return $?
}
exists_key() {
return 0
}
+ exists_partition() {
+ return 0
+ }
run main "mount"
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