Stub route discovery in network QR tests

This commit is contained in:
David Heinemeier Hansson committed 2026-09-21 10:50:25 +02:00
1 parent ef81d37a87
commit 5b22f50be3
1 file changed
+10 -5
+10 -5
View File
@@ -8,6 +8,12 @@ tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
mkdir -p "$tmp/bin"
# Loopback is never wireless, so exercise the connected-Wi-Fi fallback.
cat >"$tmp/bin/ip" <<'EOF'
#!/bin/bash
printf '1.1.1.1 dev lo\n'
EOF
cat >"$tmp/bin/nmcli" <<'EOF'
#!/bin/bash
if [[ $* == *"DEVICE,TYPE,STATE"* ]]; then
@@ -28,13 +34,13 @@ payload=$(</dev/stdin)
printf '%s' "$payload" >"$QR_PAYLOAD_FILE"
printf '## \n ## \n ##\n'
EOF
chmod +x "$tmp/bin/nmcli" "$tmp/bin/qrencode"
chmod +x "$tmp/bin/ip" "$tmp/bin/nmcli" "$tmp/bin/qrencode"
run_success_case() {
local description=$1 fields=$2 expected_payload=$3
shift 3
local output meta matrix payload arg with_meta=false
local expected_matrix expected_security expected_ssid expected_iface="*"
local expected_matrix expected_security expected_ssid expected_iface="wlan0"
for arg in "$@"; do
[[ $arg == "--meta" ]] && with_meta=true || expected_iface=$arg
@@ -49,9 +55,8 @@ run_success_case() {
meta=$(head -n1 <<<"$output")
matrix=$(tail -n +2 <<<"$output")
# The meta line leads with the shared interface, security, and SSID. With
# no interface argument the helper detects one from the live host, so that
# field is only pinned when the case pinned it.
# The metadata reports the requested interface, or the connected Wi-Fi
# interface supplied by the nmcli stub when no interface was requested.
expected_security=${expected_payload#WIFI:T:}
expected_security=${expected_security%%;*}
expected_ssid=$(head -n1 <<<"$fields")