test(ariadne): cover nextcloud maintenance failures
This commit is contained in:
parent
102eaf8d92
commit
a8b1e5ac7c
50
tests/unit/services/test_nextcloud_maintenance.py
Normal file
50
tests/unit/services/test_nextcloud_maintenance.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import types
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ariadne.k8s.exec import ExecError
|
||||||
|
from ariadne.services import nextcloud_maintenance as maintenance
|
||||||
|
|
||||||
|
|
||||||
|
def _settings(**overrides):
|
||||||
|
base = {
|
||||||
|
"nextcloud_namespace": "nextcloud",
|
||||||
|
"nextcloud_exec_timeout_sec": 30.0,
|
||||||
|
"nextcloud_url": "https://cloud.bstein.dev",
|
||||||
|
}
|
||||||
|
base.update(overrides)
|
||||||
|
return types.SimpleNamespace(**base)
|
||||||
|
|
||||||
|
|
||||||
|
def test_nextcloud_maintenance_requires_namespace(monkeypatch) -> None:
|
||||||
|
monkeypatch.setattr(maintenance, "settings", _settings(nextcloud_namespace=""))
|
||||||
|
|
||||||
|
with pytest.raises(RuntimeError, match="not configured"):
|
||||||
|
maintenance.run_maintenance(types.SimpleNamespace())
|
||||||
|
|
||||||
|
|
||||||
|
def test_nextcloud_maintenance_handles_exec_error(monkeypatch) -> None:
|
||||||
|
monkeypatch.setattr(maintenance, "settings", _settings())
|
||||||
|
|
||||||
|
class Executor:
|
||||||
|
def exec(self, *args, **kwargs):
|
||||||
|
raise ExecError("pod failed")
|
||||||
|
|
||||||
|
service = types.SimpleNamespace(_executor=Executor())
|
||||||
|
|
||||||
|
assert maintenance.run_maintenance(service) == {"status": "error", "detail": "pod failed"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_nextcloud_maintenance_handles_generic_error(monkeypatch) -> None:
|
||||||
|
monkeypatch.setattr(maintenance, "settings", _settings())
|
||||||
|
|
||||||
|
class Executor:
|
||||||
|
def exec(self, *args, **kwargs):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def fail_occ(_args):
|
||||||
|
raise ValueError("occ failed")
|
||||||
|
|
||||||
|
service = types.SimpleNamespace(_executor=Executor(), _occ=fail_occ)
|
||||||
|
|
||||||
|
assert maintenance.run_maintenance(service) == {"status": "error", "detail": "occ failed"}
|
||||||
Loading…
x
Reference in New Issue
Block a user