test(ariadne): cover cluster health helpers

This commit is contained in:
codex 2026-04-21 03:46:38 -03:00
parent 9965983322
commit d3ae03f935
2 changed files with 33 additions and 6 deletions

View File

@ -4,12 +4,10 @@ from typing import Any
from .cluster_state_contract import * from .cluster_state_contract import *
def _health_bullets( HealthRows = list[dict[str, Any]]
metrics: dict[str, Any],
nodes_summary: dict[str, Any],
workloads_health: dict[str, Any], def _health_bullets(metrics: dict[str, Any], nodes_summary: dict[str, Any], workloads_health: dict[str, Any], anomalies: HealthRows) -> list[str]:
anomalies: list[dict[str, Any]],
) -> list[str]:
bullets: list[str] = [] bullets: list[str] = []
nodes_total = metrics.get("nodes_total") nodes_total = metrics.get("nodes_total")
nodes_ready = metrics.get("nodes_ready") nodes_ready = metrics.get("nodes_ready")

View File

@ -236,3 +236,32 @@ def test_profile_builders_filter_bad_nodes_and_workload_nodes() -> None:
assert workload_profiles[0]["nodes_top"] == [("titan-1", 2), ("titan-2", 1)] assert workload_profiles[0]["nodes_top"] == [("titan-1", 2), ("titan-2", 1)]
assert workload_profiles[1]["nodes_top"] == [] assert workload_profiles[1]["nodes_top"] == []
def test_health_helpers_handle_clean_and_malformed_inputs() -> None:
bullets = health._health_bullets(
{"pods_running": 1, "pods_pending": 0, "pods_failed": 0},
{},
{"deployments": {"not_ready": 0}, "statefulsets": "bad", "daemonsets": {}},
[{"summary": ""}],
)
assert bullets == ["Pods: 1 running, 0 pending, 0 failed", "Workloads: all ready"]
workload_items = health._workload_not_ready_items(
{
"deployments": {"items": [None, {"namespace": "apps", "name": "api", "desired": 2, "ready": 1}]},
"statefulsets": {"items": "bad"},
}
)
assert workload_items == [{"kind": "deployment", "namespace": "apps", "name": "api", "desired": 2, "ready": 1}]
restarts = health._pod_restarts_top(
{
"top_restarts_1h": [
None,
{"metric": {"namespace": "apps"}, "value": 3},
{"metric": {"namespace": "apps", "pod": "api"}, "value": 2},
]
}
)
assert restarts == [{"namespace": "apps", "pod": "api", "value": 2}]