test: cover easy missing branches in report/config/credentials/ssh/wait/job
This commit is contained in:
@@ -187,3 +187,52 @@ def test_wait_ready_invalid_transport_value(monkeypatch: pytest.MonkeyPatch) ->
|
||||
)
|
||||
assert result.exit_code != 0
|
||||
assert "Unknown" in result.output or "bogus" in result.output
|
||||
|
||||
|
||||
# ── helpers (wait_module._wait_running / _wait_for_ip / branches) ───────────────────
|
||||
|
||||
|
||||
from ci_orchestrator.backends.errors import BackendError # noqa: E402
|
||||
|
||||
|
||||
class _ErrorBackend:
|
||||
def __init__(self) -> None:
|
||||
self.calls = 0
|
||||
|
||||
def is_running(self, _h: VmHandle) -> bool:
|
||||
self.calls += 1
|
||||
raise BackendError("probe boom")
|
||||
|
||||
def get_ip(self, _h: VmHandle, timeout: float = 0.0) -> str | None:
|
||||
raise BackendError("ip boom")
|
||||
|
||||
|
||||
def test_wait_running_swallows_backend_error_and_returns_false(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(wait_module.time, "sleep", lambda _s: None)
|
||||
monkeypatch.setattr(wait_module.time, "monotonic", lambda: 0.0)
|
||||
backend = _ErrorBackend()
|
||||
# deadline already passed after first iteration
|
||||
seq = iter([0.0, 1.0])
|
||||
monkeypatch.setattr(wait_module.time, "monotonic", lambda: next(seq))
|
||||
ok = wait_module._wait_running(backend, VmHandle("x"), deadline=0.5, poll=0.001) # type: ignore[arg-type]
|
||||
assert ok is False
|
||||
assert backend.calls == 1
|
||||
|
||||
|
||||
def test_wait_for_ip_returns_none_on_backend_error(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(wait_module.time, "sleep", lambda _s: None)
|
||||
seq = iter([0.0, 1.0])
|
||||
monkeypatch.setattr(wait_module.time, "monotonic", lambda: next(seq))
|
||||
backend = _ErrorBackend()
|
||||
ip = wait_module._wait_for_ip(backend, VmHandle("x"), deadline=0.5, poll=0.001) # type: ignore[arg-type]
|
||||
assert ip is None
|
||||
|
||||
|
||||
def test_normalise_guest_os_rejects_unknown() -> None:
|
||||
import click
|
||||
with pytest.raises(click.BadParameter):
|
||||
wait_module._normalise_guest_os("freebsd")
|
||||
|
||||
Reference in New Issue
Block a user