|| return $?
}
+mount_partition()
+{
+ local partition="$1"
+ local backup_path="$2"
+}
+
mount_device()
{
local config="$1"
local device=
local key=
local volume=
+ local partition=
+ local backup_path=
device=$(echo "$config" \
| jq --raw-output ".media.\"$media\".device")
|| return $?
echo "ℹ️ INFO: volume open luks-crypt-volume"
+ partition=$(echo "$config" \
+ | jq --raw-output ".media.\"$media\".partition")
+ [ "$partition" != "null" ] \
+ || errlog "missing partition for media $media in $CONFIG_FILE" \
+ || return $?
+ backup_path=$(echo "$config" \
+ | jq --raw-output ".backup_path")
+ [ "$backup_path" != "null" ] \
+ || errlog "missing backup path in $CONFIG_FILE" \
+ || return $?
+
cryptsetupargs=("open"
"--key-file $key"
"$device"
cryptsetup "${cryptsetupargs[@]}" \
|| errlog "could not open $device with $key" \
|| return $?
+
+ mount_partition "$partition" "$backup_path" || return $?
}
mount_backup()
assert_line --index 0 "⭐ START: backupmount"
}
-# bats test_tags=backupmount:start,backupmount:cmd
+# bats test_tags=backupmount:cmd
@test "failure yq command not found" {
command() {
return 1
assert_line --index 0 "❌ ERROR: command yq not found"
}
-# bats test_tags=backupmount:start,backupmount:cmd
+# bats test_tags=backupmount:cmd
@test "failure jq command not found" {
command() {
[ "$2" != "jq" ] || return 1
assert_line --index 0 "❌ ERROR: command jq not found"
}
-# bats test_tags=backupmount:start,backupmount:cmd
+# bats test_tags=backupmount:cmd
@test "failure cryptsetup command not found" {
command() {
[ "$2" != "cryptsetup" ] || return 1
assert_line --index 0 "❌ ERROR: failed to load src/config-example.yaml"
}
-# bats test_tags=backupmount:start
+# bats test_tags=backupmount:param
@test "failure missing command parameter" {
run main
assert_line --index 1 "❌ ERROR: missing command"
}
-# bats test_tags=backupmount:start
+# bats test_tags=backupmount:param
@test "failure unknown command parameter" {
run main "heyho"
assert_line --index 1 "❌ ERROR: unknown command"
}
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
@test "failure missing media" {
yq() {
echo '{}'
assert_line --index 1 "❌ ERROR: missing media in src/config-example.yaml"
}
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
@test "failure missing device for media day" {
yq() {
echo '{
assert_line --index 4 "❌ ERROR: no device found"
}
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
@test "failure missing key for media day" {
yq() {
echo '{
assert_line --index 2 "❌ ERROR: key notexistskey for media day not exists"
}
-# bats test_tags=backupmount:mount
+# bats test_tags=backupmount:config
@test "failure missing volume for media day" {
yq() {
echo '{
assert_line --index 3 "❌ ERROR: missing volume in src/config-example.yaml"
}
+# bats test_tags=backupmount:config
+@test "failure missing partition for media day" {
+ yq() {
+ echo '{
+ "backup_volume": "luks-crypt-volume",
+ "media": {
+ "day": {
+ "device": "/dev/path/to/day",
+ "key": "/path/to/key"
+ }
+ }
+ }'
+ }
+ exists_block_device() {
+ return 0
+ }
+ exists_key() {
+ return 0
+ }
+
+ 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/key"
+ assert_line --index 3 "ℹ️ INFO: volume open luks-crypt-volume"
+ assert_line --index 4 "❌ ERROR: missing partition for media day in src/config-example.yaml"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure missing backup path" {
+ yq() {
+ echo '{
+ "backup_volume": "luks-crypt-volume",
+ "media": {
+ "day": {
+ "device": "/dev/path/to/day",
+ "key": "/path/to/key",
+ "partition": "/path/to/part"
+ }
+ }
+ }'
+ }
+ exists_block_device() {
+ return 0
+ }
+ exists_key() {
+ return 0
+ }
+
+ 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/key"
+ assert_line --index 3 "ℹ️ INFO: volume open luks-crypt-volume"
+ assert_line --index 4 "❌ ERROR: missing backup path in src/config-example.yaml"
+}
+
# bats test_tags=backupmount:mount
@test "success open volume for media day" {
exists_block_device() {