aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-23 21:05:17 -0400
committerCraig Jennings <c@cjennings.net>2026-06-23 21:05:17 -0400
commit73e66b703258270a3d688a51dd90ed2f24401568 (patch)
tree17a8e146a1525912ae3761e5f269043eaa43874a /tests/unit
parentedb5016809f3bc657283d8c2402970dbbab3c5cf (diff)
downloadarchangel-73e66b703258270a3d688a51dd90ed2f24401568.tar.gz
archangel-73e66b703258270a3d688a51dd90ed2f24401568.zip
refactor(installer): extract parse_btrfs_subvol_opts helper
mount_btrfs_subvolumes and generate_btrfs_fstab each carried an identical block that composed a subvolume's mount options from BTRFS_OPTS plus the per-subvol extra flags. The two could drift out of sync. Extracted the logic into parse_btrfs_subvol_opts (pure string transform), preserving the exact behavior, and called it from both. Added bats cases covering the default, compress=no, nodatacow, nosuid, and combined paths.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_btrfs.bats35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit/test_btrfs.bats b/tests/unit/test_btrfs.bats
index 890bba2..15bf141 100644
--- a/tests/unit/test_btrfs.bats
+++ b/tests/unit/test_btrfs.bats
@@ -54,3 +54,38 @@ setup() {
[ "$status" -eq 0 ]
[ -z "$output" ]
}
+
+#############################
+# parse_btrfs_subvol_opts
+#############################
+# Composes the mount-option string for one subvolume from the shared
+# BTRFS_OPTS plus the per-subvol extra flags. Pure string transform,
+# shared by mount_btrfs_subvolumes and generate_btrfs_fstab. BTRFS_OPTS
+# is set at the top of btrfs.sh (sourced in setup), so these pin behavior
+# against the real default option string.
+
+@test "parse_btrfs_subvol_opts: no extra flags keeps the default opts" {
+ run parse_btrfs_subvol_opts "@home" ""
+ [ "$status" -eq 0 ]
+ [ "$output" = "subvol=@home,noatime,compress=zstd,space_cache=v2,discard=async" ]
+}
+
+@test "parse_btrfs_subvol_opts: compress=no drops compress=zstd" {
+ run parse_btrfs_subvol_opts "@media" "compress=no"
+ [ "$output" = "subvol=@media,noatime,space_cache=v2,discard=async" ]
+}
+
+@test "parse_btrfs_subvol_opts: nodatacow adds nodatacow and drops compress=zstd" {
+ run parse_btrfs_subvol_opts "@vms" "nodatacow"
+ [ "$output" = "subvol=@vms,noatime,space_cache=v2,discard=async,nodatacow" ]
+}
+
+@test "parse_btrfs_subvol_opts: nosuid adds nosuid,nodev and keeps compression" {
+ run parse_btrfs_subvol_opts "@tmp" "nosuid"
+ [ "$output" = "subvol=@tmp,noatime,compress=zstd,space_cache=v2,discard=async,nosuid,nodev" ]
+}
+
+@test "parse_btrfs_subvol_opts: nodatacow and nosuid combine" {
+ run parse_btrfs_subvol_opts "@x" "nodatacow,nosuid"
+ [ "$output" = "subvol=@x,noatime,space_cache=v2,discard=async,nodatacow,nosuid,nodev" ]
+}