diff options
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/test_archangel.bats | 45 | ||||
| -rw-r--r-- | tests/unit/test_config.bats | 49 |
2 files changed, 55 insertions, 39 deletions
diff --git a/tests/unit/test_archangel.bats b/tests/unit/test_archangel.bats index ccabec7..749f786 100644 --- a/tests/unit/test_archangel.bats +++ b/tests/unit/test_archangel.bats @@ -70,33 +70,9 @@ setup() { ############################# # Optional-field defaults ############################# - -@test "gather_input unattended defaults FILESYSTEM to zfs when empty" { - HOSTNAME=h - TIMEZONE=UTC - ROOT_PASSWORD=x - SELECTED_DISKS=(/dev/sda) - FILESYSTEM="" - NO_ENCRYPT=yes - gather_input >/dev/null - [ "$FILESYSTEM" = "zfs" ] -} - -@test "gather_input unattended defaults LOCALE, KEYMAP, ENABLE_SSH when empty" { - HOSTNAME=h - TIMEZONE=UTC - ROOT_PASSWORD=x - SELECTED_DISKS=(/dev/sda) - FILESYSTEM=zfs - NO_ENCRYPT=yes - LOCALE="" - KEYMAP="" - ENABLE_SSH="" - gather_input >/dev/null - [ "$LOCALE" = "en_US.UTF-8" ] - [ "$KEYMAP" = "us" ] - [ "$ENABLE_SSH" = "yes" ] -} +# Default values themselves are pinned in test_config.bats (config.sh +# is the single source of truth). The remaining test here covers the +# adjacent guarantee: gather_input doesn't clobber values the user set. @test "gather_input unattended preserves explicit non-default values" { HOSTNAME=h @@ -160,18 +136,9 @@ setup() { ############################# # Filesystem validity ############################# - -@test "gather_input unattended errors when FILESYSTEM is neither zfs nor btrfs" { - HOSTNAME=h - TIMEZONE=UTC - ROOT_PASSWORD=x - SELECTED_DISKS=(/dev/sda) - FILESYSTEM=ext4 - NO_ENCRYPT=yes - run gather_input - [ "$status" -eq 1 ] - [[ "$output" == *"Invalid FILESYSTEM"* ]] -} +# Validation moved to validate_filesystem in lib/config.sh — covered +# by test_config.bats. main() calls it between check_config and +# gather_input so a bad FILESYSTEM= never reaches install time. ############################# # RAID-level defaulting diff --git a/tests/unit/test_config.bats b/tests/unit/test_config.bats index c0c4e42..46f0236 100644 --- a/tests/unit/test_config.bats +++ b/tests/unit/test_config.bats @@ -156,3 +156,52 @@ EOF [ "$CONFIG_FILE" = "/tmp/foo.conf" ] [ -n "$RED" ] } + +############################# +# Default values sourced from config.sh +############################# +# config.sh is the single source of truth for installer defaults. The +# monolith no longer re-applies them in gather_input. These tests pin +# the values so a regression that drops a default surfaces here, not +# halfway through an unattended install. + +@test "config.sh sets defaults for FILESYSTEM, LOCALE, KEYMAP, ENABLE_SSH, NO_ENCRYPT" { + [ "$FILESYSTEM" = "zfs" ] + [ "$LOCALE" = "en_US.UTF-8" ] + [ "$KEYMAP" = "us" ] + [ "$ENABLE_SSH" = "yes" ] + [ "$NO_ENCRYPT" = "no" ] +} + +############################# +# validate_filesystem +############################# +# Called from main() between check_config and gather_input. Catches a +# typo in FILESYSTEM= from a config file before the install starts. + +@test "validate_filesystem accepts zfs" { + FILESYSTEM=zfs + run validate_filesystem + [ "$status" -eq 0 ] +} + +@test "validate_filesystem accepts btrfs" { + FILESYSTEM=btrfs + run validate_filesystem + [ "$status" -eq 0 ] +} + +@test "validate_filesystem rejects an unknown filesystem" { + FILESYSTEM=ext4 + run validate_filesystem + [ "$status" -eq 1 ] + [[ "$output" == *"Invalid FILESYSTEM"* ]] + [[ "$output" == *"ext4"* ]] +} + +@test "validate_filesystem rejects an empty FILESYSTEM" { + FILESYSTEM="" + run validate_filesystem + [ "$status" -eq 1 ] + [[ "$output" == *"Invalid FILESYSTEM"* ]] +} |
