Add coverage gap tests for command functionalities
- Implement tests for disk alert JSON output to include a message field when below threshold. - Add tests for runner status when Gitea is online but no webhook URL is provided. - Introduce tests for job report details to ensure no error line appears when there are no failure events. - Add tests to skip empty JSONL files in job report listing.
This commit is contained in:
@@ -659,3 +659,49 @@ def test_runner_pruned_old_entries(
|
||||
cli, ["monitor", "runner", "--state-dir", str(tmp_path)]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
# ── NEW: coverage gap tests ──────────────────────────────────────────────────
|
||||
|
||||
|
||||
def test_disk_alert_json_includes_message_field(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Lines 186-187: disk below threshold + --json → JSON has 'message' key, exit 1."""
|
||||
monkeypatch.setattr(mon.shutil, "disk_usage", lambda _p: _fake_usage(free_gb=5))
|
||||
result = CliRunner().invoke(
|
||||
cli, ["monitor", "disk", "--min-free-gb", "50", "--json"]
|
||||
)
|
||||
assert result.exit_code == 1
|
||||
payload = json.loads(result.output.strip())
|
||||
assert payload["status"] == "alert"
|
||||
assert "message" in payload
|
||||
assert "below" in payload["message"]
|
||||
|
||||
|
||||
def test_runner_running_gitea_online_no_webhook(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
"""Lines 398->402: online==0 but no webhook_url → branch skips _post_webhook,
|
||||
continues to return (line 402). Covers the 398->402 branch (webhook_url falsy)."""
|
||||
monkeypatch.setattr(mon, "_service_status", lambda _s: "Running")
|
||||
monkeypatch.setattr(mon, "_gitea_runners_online", lambda *_a, **_kw: 0)
|
||||
|
||||
class _Store:
|
||||
def get(self, _target: str) -> Any:
|
||||
from ci_orchestrator.credentials import Credential
|
||||
return Credential("u", "tok")
|
||||
|
||||
import ci_orchestrator.credentials as creds
|
||||
monkeypatch.setattr(creds, "KeyringCredentialStore", _Store)
|
||||
|
||||
result = CliRunner().invoke(
|
||||
cli,
|
||||
[
|
||||
"monitor", "runner",
|
||||
"--state-dir", str(tmp_path),
|
||||
"--gitea-url", "https://g/",
|
||||
"--gitea-credential-target", "tgt",
|
||||
# no --webhook-url → webhook_url is ""
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert "0 online runners" in result.output
|
||||
|
||||
Reference in New Issue
Block a user