test(ariadne): cover cluster health helpers
This commit is contained in:
parent
9965983322
commit
d3ae03f935
@ -4,12 +4,10 @@ from typing import Any
|
||||
|
||||
from .cluster_state_contract import *
|
||||
|
||||
def _health_bullets(
|
||||
metrics: dict[str, Any],
|
||||
nodes_summary: dict[str, Any],
|
||||
workloads_health: dict[str, Any],
|
||||
anomalies: list[dict[str, Any]],
|
||||
) -> list[str]:
|
||||
HealthRows = list[dict[str, Any]]
|
||||
|
||||
|
||||
def _health_bullets(metrics: dict[str, Any], nodes_summary: dict[str, Any], workloads_health: dict[str, Any], anomalies: HealthRows) -> list[str]:
|
||||
bullets: list[str] = []
|
||||
nodes_total = metrics.get("nodes_total")
|
||||
nodes_ready = metrics.get("nodes_ready")
|
||||
|
||||
@ -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[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}]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user