askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
test_release_gate_script.py · 1.6 KB · 39 lines
| 1 | """scripts/release_gate.sh is the pre-push/pre-tag gate (see CONTRIBUTING.md, "Release gate"). |
| 2 | |
| 3 | It needs Docker, so pytest never runs it; this only keeps it from rotting unnoticed: present, executable, |
| 4 | syntactically valid bash, still offering its stages, and still cleaning up only what it created. |
| 5 | """ |
| 6 | import os |
| 7 | import shutil |
| 8 | import subprocess |
| 9 | from pathlib import Path |
| 10 | |
| 11 | import pytest |
| 12 | |
| 13 | SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "release_gate.sh" |
| 14 | |
| 15 | |
| 16 | def test_release_gate_script_exists_and_is_executable(): |
| 17 | assert SCRIPT.is_file() |
| 18 | assert os.access(SCRIPT, os.X_OK) |
| 19 | |
| 20 | |
| 21 | def test_release_gate_script_has_its_stages_and_safety_rails(): |
| 22 | text = SCRIPT.read_text() |
| 23 | assert text.startswith("#!/usr/bin/env bash") |
| 24 | assert "set -euo pipefail" in text |
| 25 | for stage in ("fresh", "upgrade", "node", "all"): |
| 26 | assert f"{stage})" in text or f"|{stage}" in text or f"{stage}|" in text, stage |
| 27 | if stage != "all": |
| 28 | assert f"stage_{stage}()" in text |
| 29 | assert 'PREFIX="gate-' in text # everything it creates is named gate-... |
| 30 | assert "trap cleanup EXIT" in text # ...and removed on exit |
| 31 | |
| 32 | |
| 33 | @pytest.mark.skipif(shutil.which("bash") is None, reason="bash not installed") |
| 34 | def test_release_gate_script_is_valid_bash_and_rejects_an_unknown_stage(): |
| 35 | assert subprocess.run(["bash", "-n", str(SCRIPT)]).returncode == 0 |
| 36 | # an unknown stage is refused before it looks for Docker or creates anything |
| 37 | result = subprocess.run(["bash", str(SCRIPT), "nonsense"], capture_output=True, text=True) |
| 38 | assert result.returncode == 2 |
| 39 | assert "usage" in result.stderr |