aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-22 20:12:14 -0500
committerCraig Jennings <c@cjennings.net>2026-05-22 20:12:14 -0500
commit0f8bbc7c1e2c2f6fec0b17753ac0d9c4a3ad4317 (patch)
tree3a2015786254ac90610e221f26517aaf58e7ff26 /tests
parent0a57d75d3947fddd6c6ab62924c52a456f4776b0 (diff)
downloadarchangel-0f8bbc7c1e2c2f6fec0b17753ac0d9c4a3ad4317.tar.gz
archangel-0f8bbc7c1e2c2f6fec0b17753ac0d9c4a3ad4317.zip
fix(test): fail clearly when the VM forward port is taken
A test run launched qemu without first checking the SSH forward port, so a collision with another VM already holding it surfaced only as an opaque "Failed to start VM," with qemu unable to bind and no hint why. I added a port_in_use check in run_test before the launch: it errors with the port number and the SSH_PORT override to set, records the failure, and moves on. The check lives in run_test, not start_vm, because start_vm runs in a command substitution (vm_pid=$(start_vm ...)) where this harness's non-exiting error() would be captured as the PID instead of failing the run. The pure half, port_listening_in, takes an `ss -tln` snapshot as a string so it's unit-testable.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_test_install.bats31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/unit/test_test_install.bats b/tests/unit/test_test_install.bats
index 6b911af..bc4a63e 100644
--- a/tests/unit/test_test_install.bats
+++ b/tests/unit/test_test_install.bats
@@ -235,3 +235,34 @@ EOF
source "${BATS_TEST_DIRNAME}/../../scripts/test-install.sh"
[ "$SSH_PORT" = "2222" ]
}
+
+#############################
+# port_listening_in (pure half of the port-in-use guard)
+#############################
+# The live ss query lives in port_in_use; this pure predicate takes an
+# `ss -tln` snapshot as a string so it's testable with fixtures.
+
+@test "port_listening_in detects a port present in ss output" {
+ run port_listening_in 2222 "LISTEN 0 4096 0.0.0.0:2222 0.0.0.0:*"
+ [ "$status" -eq 0 ]
+}
+
+@test "port_listening_in returns 1 when the port is absent" {
+ run port_listening_in 2222 "LISTEN 0 4096 0.0.0.0:22 0.0.0.0:*"
+ [ "$status" -eq 1 ]
+}
+
+@test "port_listening_in does not match a port that is only a substring" {
+ run port_listening_in 2222 "LISTEN 0 4096 0.0.0.0:12222 0.0.0.0:*"
+ [ "$status" -eq 1 ]
+}
+
+@test "port_listening_in matches an IPv6 listener" {
+ run port_listening_in 2222 "LISTEN 0 4096 [::]:2222 [::]:*"
+ [ "$status" -eq 0 ]
+}
+
+@test "port_listening_in returns 1 on empty ss output" {
+ run port_listening_in 2222 ""
+ [ "$status" -eq 1 ]
+}