From dc4e76c90d9cb58058b78ef8195a4c7f9125928f Mon Sep 17 00:00:00 2001 From: codex Date: Tue, 21 Apr 2026 03:28:43 -0300 Subject: [PATCH] test(ariadne): cover Kubernetes pod selector edges --- tests/test_k8s_pods.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_k8s_pods.py b/tests/test_k8s_pods.py index ac419bd..1c7a085 100644 --- a/tests/test_k8s_pods.py +++ b/tests/test_k8s_pods.py @@ -17,6 +17,23 @@ def test_list_pods_encodes_selector(monkeypatch) -> None: assert "labelSelector=app%3Dnextcloud" in captured["path"] +def test_list_pods_rejects_missing_namespace() -> None: + with pytest.raises(pods_module.PodSelectionError, match="namespace missing"): + pods_module.list_pods(" ", "app=nextcloud") + + +def test_parse_start_time_handles_empty_invalid_and_naive_values() -> None: + assert pods_module._parse_start_time(None) == 0.0 + assert pods_module._parse_start_time("not-a-date") == 0.0 + assert pods_module._parse_start_time("2026-01-20T00:00:00") > 0 + + +def test_ready_helper_handles_malformed_conditions() -> None: + assert pods_module._is_ready({"status": {"phase": "Running"}}) is False + assert pods_module._is_ready({"status": {"phase": "Running", "conditions": [None]}}) is False + assert pods_module._is_ready({"status": {"phase": "Running", "conditions": [{"type": "ContainersReady"}]}}) is False + + def test_select_pod_picks_ready_latest(monkeypatch) -> None: payload = { "items": [ @@ -57,3 +74,28 @@ def test_select_pod_ignores_non_ready(monkeypatch) -> None: with pytest.raises(pods_module.PodSelectionError): pods_module.select_pod("demo", "app=test") + + +def test_select_pod_skips_deleting_and_blank_names(monkeypatch) -> None: + payload = { + "items": [ + { + "metadata": {"name": "deleting", "deletionTimestamp": "2026-01-20T00:00:00Z"}, + "status": {"phase": "Running", "conditions": [{"type": "Ready", "status": "True"}]}, + }, + { + "metadata": {"name": " "}, + "status": {"phase": "Running", "conditions": [{"type": "Ready", "status": "True"}]}, + }, + { + "metadata": {"name": "ready"}, + "status": {"phase": "Running", "nodeName": "titan-1", "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 == "ready" + assert pod.node == "titan-1"