60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from ariadne.k8s import pods as pods_module
|
||
|
|
|
||
|
|
|
||
|
|
def test_list_pods_encodes_selector(monkeypatch) -> None:
|
||
|
|
captured = {}
|
||
|
|
|
||
|
|
def fake_get_json(path: str):
|
||
|
|
captured["path"] = path
|
||
|
|
return {"items": []}
|
||
|
|
|
||
|
|
monkeypatch.setattr(pods_module, "get_json", fake_get_json)
|
||
|
|
pods_module.list_pods("demo", "app=nextcloud")
|
||
|
|
assert "labelSelector=app%3Dnextcloud" in captured["path"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_select_pod_picks_ready_latest(monkeypatch) -> None:
|
||
|
|
payload = {
|
||
|
|
"items": [
|
||
|
|
{
|
||
|
|
"metadata": {"name": "old-pod"},
|
||
|
|
"status": {
|
||
|
|
"phase": "Running",
|
||
|
|
"startTime": "2026-01-19T00:00:00Z",
|
||
|
|
"conditions": [{"type": "Ready", "status": "True"}],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"metadata": {"name": "new-pod"},
|
||
|
|
"status": {
|
||
|
|
"phase": "Running",
|
||
|
|
"startTime": "2026-01-20T00:00:00Z",
|
||
|
|
"conditions": [{"type": "Ready", "status": "True"}],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
monkeypatch.setattr(pods_module, "get_json", lambda *_args, **_kwargs: payload)
|
||
|
|
pod = pods_module.select_pod("demo", "app=test")
|
||
|
|
assert pod.name == "new-pod"
|
||
|
|
|
||
|
|
|
||
|
|
def test_select_pod_ignores_non_ready(monkeypatch) -> None:
|
||
|
|
payload = {
|
||
|
|
"items": [
|
||
|
|
{
|
||
|
|
"metadata": {"name": "pending"},
|
||
|
|
"status": {"phase": "Pending"},
|
||
|
|
},
|
||
|
|
]
|
||
|
|
}
|
||
|
|
monkeypatch.setattr(pods_module, "get_json", lambda *_args, **_kwargs: payload)
|
||
|
|
|
||
|
|
with pytest.raises(pods_module.PodSelectionError):
|
||
|
|
pods_module.select_pod("demo", "app=test")
|