test: preserve quality and websocket evidence (#107)
Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"""Failure-injection checks for CI quality gates."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -60,6 +61,22 @@ def gate(directory, budget=5, exit_code=0):
|
||||
)
|
||||
|
||||
|
||||
def assert_auditable_failure(result, directory, name, expected):
|
||||
report = json.loads((directory / "report.json").read_text(encoding="utf-8"))
|
||||
assert result.returncode != 0, f"{name} must fail"
|
||||
assert report["status"] == "failed"
|
||||
assert expected in report["failures"]
|
||||
assert expected in result.stdout
|
||||
print(result.stdout.strip())
|
||||
|
||||
if evidence := os.getenv("GOCHAT_QUALITY_DIR"):
|
||||
target = Path(evidence)
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
(target / f"{name}.json").write_text(
|
||||
json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
directory = Path(temp)
|
||||
@@ -97,10 +114,14 @@ def main():
|
||||
{"Action": "fail", "Package": "github.com/gochat/gochat/internal/ws", "Test": "TestRelay"}
|
||||
],
|
||||
)
|
||||
assert gate(directory).returncode != 0, "failed test evidence must fail"
|
||||
assert_auditable_failure(
|
||||
gate(directory), directory, "action-fail", "test evidence contains 1 failed test events"
|
||||
)
|
||||
|
||||
write_fixtures(directory)
|
||||
assert gate(directory, exit_code=2).returncode != 0, "non-zero go test status must fail"
|
||||
assert_auditable_failure(
|
||||
gate(directory, exit_code=2), directory, "nonzero-test-exit", "go test exited with 2"
|
||||
)
|
||||
|
||||
health = directory / "health.json"
|
||||
health.write_text(
|
||||
|
||||
Reference in New Issue
Block a user