diff --git a/tests/test_install_script.py b/tests/test_install_script.py index d78302a..f7f039c 100644 --- a/tests/test_install_script.py +++ b/tests/test_install_script.py @@ -634,15 +634,48 @@ def test_het_controleadres_volgt_het_bind_adres(bind, verwacht, tmp_path): assert uit.strip().splitlines()[-1] == verwacht, uit -def _sh(fragment, tmp_path): +def _sh(fragment, tmp_path, met_nep_curl=False): """Laadt install.sh en draait een fragment; geen terminal in het spel.""" + import os script = tmp_path / "frag.sh" script.write_text(f"set --\nSU_INSTALL_ALLEEN_FUNCTIES=1 . {SCRIPT}\n{fragment}\n") + env = dict(os.environ) + if met_nep_curl: + env["PATH"] = f"{_nep_curl(tmp_path)}{os.pathsep}{env.get('PATH', '')}" r = subprocess.run(["sh", str(script)], capture_output=True, text=True, - timeout=60, stdin=subprocess.DEVNULL) + timeout=60, stdin=subprocess.DEVNULL, env=env) return r.stdout + r.stderr +def _nep_curl(tmp_path): + """Een map met een eigen `curl`, zodat deze tests overal hetzelfde doen. + + De CI-runner draait in python:3.12-slim en heeft geen curl. Zonder dit + faalde elke poging daar en toetsten deze tests niets meer dan "curl + ontbreekt". Wat ze wél moeten toetsen is welk adres het script opvraagt, en + dat legt dit schilletje vast. + """ + bin_dir = tmp_path / "nepbin" + if bin_dir.exists(): + return str(bin_dir) + bin_dir.mkdir() + shim = bin_dir / "curl" + shim.write_text( + "#!/usr/bin/env python3\n" + "import sys, urllib.request\n" + "url = next((a for a in sys.argv[1:] if a.startswith('http')), None)\n" + "if not url:\n" + " sys.exit(2)\n" + "try:\n" + " with urllib.request.urlopen(url, timeout=2) as r:\n" + " sys.stdout.write(r.read().decode('utf-8', 'replace'))\n" + "except Exception:\n" + " sys.exit(22)\n", + encoding="utf-8") + shim.chmod(0o755) + return str(bin_dir) + + def _server(poort_uit, pad="/healthz", inhoud=b'{"version":"9.9.9"}'): """Een minimale HTTP-server op 127.0.0.1 die één pad kent.""" import http.server @@ -674,7 +707,7 @@ def test_wachten_slaagt_zodra_de_server_antwoordt(tmp_path): try: uit = _sh(f'DROOG=0; BIND="127.0.0.1"; POORT={poort[0]}; DOEL="{tmp_path}"\n' 'SU_WACHT_POGINGEN=3 wacht_op_gereed && echo "UITKOMST=gereed"\n', - tmp_path) + tmp_path, met_nep_curl=True) finally: srv.shutdown() assert "UITKOMST=gereed" in uit, uit @@ -689,7 +722,7 @@ def test_wachten_kijkt_naar_het_ingestelde_adres_niet_naar_loopback(tmp_path): try: uit = _sh(f'DROOG=0; BIND="10.255.255.1"; POORT={poort[0]}; DOEL="{tmp_path}"\n' 'SU_WACHT_POGINGEN=1 wacht_op_gereed || echo "UITKOMST=niet-gereed"\n', - tmp_path) + tmp_path, met_nep_curl=True) finally: srv.shutdown() assert "UITKOMST=niet-gereed" in uit, uit @@ -699,7 +732,7 @@ def test_wachten_kijkt_naar_het_ingestelde_adres_niet_naar_loopback(tmp_path): def test_wachten_faalt_als_er_niets_luistert(tmp_path): uit = _sh(f'DROOG=0; BIND="127.0.0.1"; POORT=1; DOEL="{tmp_path}"\n' 'SU_WACHT_POGINGEN=1 wacht_op_gereed || echo "UITKOMST=niet-gereed"\n', - tmp_path) + tmp_path, met_nep_curl=True) assert "UITKOMST=niet-gereed" in uit, uit assert "logs --tail" in uit, "geen aanwijzing hoe je verder kijkt"