]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add test for failure partion mount
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 17:28:54 +0000 (19:28 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 17:28:54 +0000 (19:28 +0200)
src/backupmount
tests/backupmount_tests.bats

index 2a91485bc273c7f80c65578b2c4f1d121639d9d4..c10d48f9ed2f26e7a116645cfef519d5f41913f4 100755 (executable)
@@ -55,9 +55,13 @@ mount_partition()
        local backup_path="$2"
 
        echo "ℹ️ INFO: create backup path $backup_path"
-       mkdir --parents "$backup_path"
+       mkdir --parents "$backup_path" \
+               || errlog "could not create backup path $backup_path" \
+               || return $?
        echo "ℹ️ INFO: mount $partition to $backup_path"
-       mount "$partition" "$backup_path"
+       mount "$partition" "$backup_path" \
+               || errlog "could not mount $partition to $backup_path" \
+               || return $?
 }
 
 mount_device()
index a4d2b0709a4af1c1b18dc93bd3a6de60c49ad5b8..a3dda877ced32130acdcbfc9dd5e3ebeee3ac163 100755 (executable)
@@ -394,4 +394,63 @@ teardown() {
        assert_equal "$(awk 'NR==1 {print; exit}' "$MOUNT_LOG")" "2"
        assert_equal "$(awk 'NR==2 {print; exit}' "$MOUNT_LOG")" "/dev/path/to/partday"
        assert_equal "$(awk 'NR==3 {print; exit}' "$MOUNT_LOG")" "build/test"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure mount partition mkdir failed" {
+       exists_block_device() {
+               return 0
+       }
+       exists_key() {
+               return 0
+       }
+       cryptsetup() {
+               return 0
+       }
+       exists_partition() {
+               return 0
+       }
+       mkdir() {
+               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 "ℹ️ INFO: create backup path build/test"
+       assert_line --index 5 "❌ ERROR: could not create backup path build/test"
+}
+
+# bats test_tags=backupmount:mount
+@test "failure mount partition failed" {
+       exists_block_device() {
+               return 0
+       }
+       exists_key() {
+               return 0
+       }
+       cryptsetup() {
+               return 0
+       }
+       exists_partition() {
+               return 0
+       }
+       mount() {
+               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 "ℹ️ INFO: create backup path build/test"
+       assert_line --index 5 "ℹ️ INFO: mount /dev/path/to/partday to build/test"
+       assert_line --index 6 "❌ ERROR: could not mount /dev/path/to/partday to build/test"
 }
\ No newline at end of file