aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-19 02:19:04 -0500
committerCraig Jennings <c@cjennings.net>2026-05-19 02:19:04 -0500
commitb6d737fc9e3cee641afe7b855c5356122537850b (patch)
tree75d33c59bcee47fe97a0fd0ace5398de98dd6c9f /tests/unit
parent33579ee72ed97a671a898267555a50fb8411144b (diff)
downloadarchangel-b6d737fc9e3cee641afe7b855c5356122537850b.tar.gz
archangel-b6d737fc9e3cee641afe7b855c5356122537850b.zip
refactor: wire validate_config into the unattended install path
validate_config in lib/config.sh was unreachable from main(). Its empty-field checks duplicated four lines in gather_input's unattended branch. validate_config also has two checks gather_input doesn't: that every entry in SELECTED_DISKS is a real block device, and that TIMEZONE exists under /usr/share/zoneinfo. Neither check ever ran. A config with a typo'd disk path slipped past gather_input and surfaced as an obscure sgdisk error inside the destructive partitioning step. I wired validate_config into main() after validate_filesystem, gated on UNATTENDED so it only runs against an already-loaded config. I dropped the four duplicate empty-field checks from gather_input's unattended branch. The filesystem-specific passphrase checks stay there because they're coupled to the FILESYSTEM branch logic. validate_config reports every missing field at once instead of dying on the first. A config with five missing fields tells you all five in one pass. I removed the four corresponding gather_input bats tests. validate_config's existing unit tests in test_config.bats already cover their assertions. Bats: 178 → 174.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_archangel.bats63
1 files changed, 9 insertions, 54 deletions
diff --git a/tests/unit/test_archangel.bats b/tests/unit/test_archangel.bats
index 749f786..c7bbc56 100644
--- a/tests/unit/test_archangel.bats
+++ b/tests/unit/test_archangel.bats
@@ -1,12 +1,15 @@
#!/usr/bin/env bats
# Unit tests for the installer/archangel monolith.
#
-# Coverage scope: gather_input() in unattended mode — the validation
-# of required config values, defaulting of optional ones, and the
-# filesystem-specific encryption checks. The interactive branch
-# (everything reachable via `if [[ "$UNATTENDED" != true ]]`) is not
-# unit-tested per the project's testing-strategy.org policy on
-# fzf / arch-chroot / mkfs / cryptsetup wrappers.
+# Coverage scope: gather_input() in unattended mode — defaulting of
+# optional values, preservation of explicit ones, and the
+# filesystem-specific encryption checks. Required-field, disk, and
+# timezone validation moved to validate_config (called from main
+# before gather_input); its coverage lives in test_config.bats.
+# The interactive branch (everything reachable via
+# `if [[ "$UNATTENDED" != true ]]`) is not unit-tested per the
+# project's testing-strategy.org policy on fzf / arch-chroot /
+# mkfs / cryptsetup wrappers.
#
# Sourcing archangel relies on the source-guard at the bottom of
# the script: when sourced, function definitions load but main is
@@ -20,54 +23,6 @@ setup() {
}
#############################
-# Required-field validation
-#############################
-
-@test "gather_input unattended errors when HOSTNAME is missing" {
- HOSTNAME=""
- TIMEZONE=UTC
- ROOT_PASSWORD=secret
- SELECTED_DISKS=(/dev/sda)
- NO_ENCRYPT=yes
- run gather_input
- [ "$status" -eq 1 ]
- [[ "$output" == *"HOSTNAME"* ]]
-}
-
-@test "gather_input unattended errors when TIMEZONE is missing" {
- HOSTNAME=h
- TIMEZONE=""
- ROOT_PASSWORD=secret
- SELECTED_DISKS=(/dev/sda)
- NO_ENCRYPT=yes
- run gather_input
- [ "$status" -eq 1 ]
- [[ "$output" == *"TIMEZONE"* ]]
-}
-
-@test "gather_input unattended errors when ROOT_PASSWORD is missing" {
- HOSTNAME=h
- TIMEZONE=UTC
- ROOT_PASSWORD=""
- SELECTED_DISKS=(/dev/sda)
- NO_ENCRYPT=yes
- run gather_input
- [ "$status" -eq 1 ]
- [[ "$output" == *"ROOT_PASSWORD"* ]]
-}
-
-@test "gather_input unattended errors when SELECTED_DISKS is empty" {
- HOSTNAME=h
- TIMEZONE=UTC
- ROOT_PASSWORD=secret
- SELECTED_DISKS=()
- NO_ENCRYPT=yes
- run gather_input
- [ "$status" -eq 1 ]
- [[ "$output" == *"DISKS"* ]]
-}
-
-#############################
# Optional-field defaults
#############################
# Default values themselves are pinned in test_config.bats (config.sh