aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-19 12:24:43 -0500
committerCraig Jennings <c@cjennings.net>2026-05-19 12:24:43 -0500
commite49a95254d439e5e83c05756a3bc92e4575360b0 (patch)
treefd388cb615bfba9ca645d2114ef09c6dbd23813f /tests
parente2eb958c4fab1d61263b724eebd861489af73359 (diff)
downloadarchangel-e49a95254d439e5e83c05756a3bc92e4575360b0.tar.gz
archangel-e49a95254d439e5e83c05756a3bc92e4575360b0.zip
refactor: lift FILES= keyfile sed to ensure_initramfs_files helper
btrfs.sh's configure_btrfs_initramfs had a six-line inline that ensured mkinitcpio.conf's FILES= line listed the LUKS keyfile: sed-replace the existing FILES= line, then grep + append as a fallback when no FILES= line existed. The pattern is mkinitcpio-specific and self-healing rather than error-on-miss (FILES= is optional in mkinitcpio.conf, so missing means "no extra files," not a broken config). I lifted the block into ensure_initramfs_files in lib/common.sh next to prepend_grub_cmdline_linux, then collapsed the btrfs.sh call site to a single ensure_initramfs_files line. Added three bats tests for the three cases (FILES= present and empty, FILES= present with a different value, FILES= absent entirely). Bats: 174 → 177. No behavior change. The helper's logic matches the inline byte-for-byte: same sed pattern, same grep fallback, same final state.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_common.bats47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/unit/test_common.bats b/tests/unit/test_common.bats
index abe3938..8ce7280 100644
--- a/tests/unit/test_common.bats
+++ b/tests/unit/test_common.bats
@@ -473,3 +473,50 @@ Boot0001* ZFSBootMenu"
! grep -q 'cryptdevice' "$f"
rm -f "$f"
}
+
+#############################
+# ensure_initramfs_files
+#############################
+# ensure_initramfs_files sets mkinitcpio.conf's FILES= line to the
+# given value, replacing an existing line or appending one if absent.
+# Self-healing rather than error-on-miss: FILES= is optional, so a
+# missing line means "no extra files," not a broken config.
+
+@test "ensure_initramfs_files replaces an empty FILES= line" {
+ local f
+ f=$(mktemp)
+ printf '%s\n' 'FILES=()' > "$f"
+
+ ensure_initramfs_files "/etc/luks.key" "$f"
+
+ grep -qF 'FILES=(/etc/luks.key)' "$f"
+ rm -f "$f"
+}
+
+@test "ensure_initramfs_files replaces a FILES= line that lists a different value" {
+ local f
+ f=$(mktemp)
+ printf '%s\n' 'FILES=(/etc/old-key)' > "$f"
+
+ ensure_initramfs_files "/etc/luks.key" "$f"
+
+ grep -qF 'FILES=(/etc/luks.key)' "$f"
+ ! grep -qF '/etc/old-key' "$f"
+ rm -f "$f"
+}
+
+@test "ensure_initramfs_files appends FILES= when the line is absent" {
+ local f
+ f=$(mktemp)
+ printf '%s\n' \
+ 'MODULES=()' \
+ 'BINARIES=()' \
+ 'HOOKS=(base udev)' > "$f"
+
+ ensure_initramfs_files "/etc/luks.key" "$f"
+
+ grep -qF 'FILES=(/etc/luks.key)' "$f"
+ grep -qF 'MODULES=()' "$f"
+ grep -qF 'HOOKS=(base udev)' "$f"
+ rm -f "$f"
+}