aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test_archangel.bats
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-23 04:08:53 -0500
committerCraig Jennings <c@cjennings.net>2026-05-23 04:08:53 -0500
commit98fc424f7edb26314ffe124d3bc24549146a06d5 (patch)
treed0bfa15c8ac6bcfe0fc7d219e65fe37396a3af70 /tests/unit/test_archangel.bats
parent3165c50fed266fef0b388190296c149c0ae0ee47 (diff)
downloadarchangel-98fc424f7edb26314ffe124d3bc24549146a06d5.tar.gz
archangel-98fc424f7edb26314ffe124d3bc24549146a06d5.zip
test: cover disk_in_use and network_available failure paths
These two boundary functions backed the pre-flight guards from #215 but had no unit coverage of their own. The VM harness exercised them instead. I added 7 bats tests that mock the system commands they query, so the real branching logic runs. test_disk.bats covers disk_in_use across mountpoint, active swap, imported-zpool member, and idle — that's the gate that refuses to wipe an already-mounted disk. test_archangel.bats covers network_available for DNS failure, TCP-connect failure, and success, the check that fails the install before pacstrap. The /proc/mdstat-positive branch and the live probes stay in the VM harness, since neither drives cleanly without writing to /proc or hitting the network. Suite 238 to 245, lint clean.
Diffstat (limited to 'tests/unit/test_archangel.bats')
-rw-r--r--tests/unit/test_archangel.bats29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit/test_archangel.bats b/tests/unit/test_archangel.bats
index c38dcb8..645b6e6 100644
--- a/tests/unit/test_archangel.bats
+++ b/tests/unit/test_archangel.bats
@@ -372,3 +372,32 @@ setup() {
run validate_install_targets
[ "$status" -eq 0 ]
}
+
+#############################
+# network_available
+#############################
+# The two probes it composes — DNS via getent and a TCP-443 open via
+# timeout+bash /dev/tcp — are the system boundary; mocking them drives the
+# fail-fast wiring without a live network. The real probe runs in the VM
+# harness. These pin the "network failure before pacstrap" error path that
+# validate_install_targets surfaces.
+
+@test "network_available returns 1 when DNS resolution fails" {
+ getent() { return 1; }
+ run network_available
+ [ "$status" -eq 1 ]
+}
+
+@test "network_available returns 1 when DNS resolves but the TCP connect fails" {
+ getent() { return 0; }
+ timeout() { return 1; }
+ run network_available
+ [ "$status" -eq 1 ]
+}
+
+@test "network_available returns 0 when DNS resolves and the TCP connect opens" {
+ getent() { return 0; }
+ timeout() { return 0; }
+ run network_available
+ [ "$status" -eq 0 ]
+}