aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test_disk.bats
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-26 01:08:50 -0500
committerCraig Jennings <c@cjennings.net>2026-04-26 01:08:50 -0500
commit6b65665eca8a4b36b0b6eae4d761fccd7b4c1fc4 (patch)
tree69cbf8bf23d4d97c89979909d2f96f799ced92e2 /tests/unit/test_disk.bats
parentbdda6b17c83e0e298c76bbaf146f082218389cd8 (diff)
downloadarchangel-6b65665eca8a4b36b0b6eae4d761fccd7b4c1fc4.tar.gz
archangel-6b65665eca8a4b36b0b6eae4d761fccd7b4c1fc4.zip
refactor: extract get_raid_level fzf preview into raid.sh helper
`get_raid_level()` carried a 98-line inline fzf `--preview` shell snippet that contained five nearly-parallel `case` branches emitting per-level preview text, plus three exported variables (`RAID_DISK_COUNT`, `RAID_TOTAL_GB`, `RAID_SMALLEST_GB`) just to pass values into the fzf preview subshell. The inline shell-in-shell had no syntax highlighting, no shellcheck on the inner snippet, and any edit to preview copy meant editing inside a single-quoted argument. I extracted the per-level text into a new `raid_preview(level, disk_count, total_gb, smallest_gb)` helper in `lib/raid.sh`. It reuses the existing `raid_fault_tolerance` and `raid_usable_bytes` primitives for the data lines instead of redoing the arithmetic inline. That keeps the math in one place. The fzf `--preview` argument is now a one-liner that calls `raid_preview` with the sizing values, and the env-var exports are gone. `export -f raid_preview raid_fault_tolerance raid_usable_bytes` makes the functions visible in fzf's preview subshell. I verified this against a fresh `bash -c` subshell, which is what fzf spawns internally. `get_raid_level()` shrinks from 144 to 49 lines. Preview text is now bats-tested. Added 8 unit tests across the 5 RAID levels (headline, fault-tolerance line, computed usable space), mixed-size handling for mirror (smallest disk, not average), unknown level returning 1 with empty output, and a sanity loop confirming every valid level produces non-empty output. No behavior change. The preview pane shows the same text, the same level options, the same selected output. The pure logic in `lib/raid.sh` is unchanged.
Diffstat (limited to 'tests/unit/test_disk.bats')
0 files changed, 0 insertions, 0 deletions