feat(diagnose): Update Consul client to fetch health check output and display diagnostics
This commit is contained in:
@@ -62,3 +62,47 @@ def test_get_cluster_services(mock_get):
|
||||
node3 = next(s for s in services if s["node"] == "node3")
|
||||
assert node3["role"] == "replica"
|
||||
assert node3["status"] == "critical"
|
||||
|
||||
@patch("requests.get")
|
||||
def test_get_cluster_services_with_errors(mock_get):
|
||||
"""Test fetching services with detailed health check output."""
|
||||
mock_navidrome = [
|
||||
{
|
||||
"Node": {"Node": "node1", "Address": "192.168.1.101"},
|
||||
"Service": {"Service": "navidrome", "Port": 4533, "ID": "navidrome-1"},
|
||||
"Checks": [
|
||||
{"Status": "passing", "Output": "HTTP GET http://192.168.1.101:4533/app: 200 OK"}
|
||||
]
|
||||
}
|
||||
]
|
||||
mock_replicas = [
|
||||
{
|
||||
"Node": {"Node": "node3", "Address": "192.168.1.103"},
|
||||
"Service": {"Service": "replica-navidrome", "Port": 4533, "ID": "replica-2"},
|
||||
"Checks": [
|
||||
{"Status": "critical", "Output": "HTTP GET http://192.168.1.103:4533/app: 500 Internal Server Error"}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
def side_effect(url, params=None, timeout=None):
|
||||
if "health/service/navidrome" in url:
|
||||
m = MagicMock()
|
||||
m.json.return_value = mock_navidrome
|
||||
m.raise_for_status.return_value = None
|
||||
return m
|
||||
elif "health/service/replica-navidrome" in url:
|
||||
m = MagicMock()
|
||||
m.json.return_value = mock_replicas
|
||||
m.raise_for_status.return_value = None
|
||||
return m
|
||||
return MagicMock()
|
||||
|
||||
mock_get.side_effect = side_effect
|
||||
|
||||
services = consul_client.get_cluster_services("http://consul:8500")
|
||||
|
||||
node3 = next(s for s in services if s["node"] == "node3")
|
||||
assert node3["status"] == "critical"
|
||||
assert "500 Internal Server Error" in node3["check_output"]
|
||||
|
||||
|
||||
@@ -29,3 +29,32 @@ def test_format_node_table():
|
||||
assert "node1" in table
|
||||
assert "primary" in table
|
||||
assert "passing" in table
|
||||
|
||||
def test_format_diagnostics():
|
||||
"""Test the diagnostics section generation."""
|
||||
nodes = [
|
||||
{
|
||||
"node": "node3",
|
||||
"status": "critical",
|
||||
"check_output": "500 Internal Error",
|
||||
"litefs_error": "Connection Timeout"
|
||||
}
|
||||
]
|
||||
diagnostics = output_formatter.format_diagnostics(nodes, use_color=False)
|
||||
assert "DIAGNOSTICS" in diagnostics
|
||||
assert "node3" in diagnostics
|
||||
assert "500 Internal Error" in diagnostics
|
||||
assert "Connection Timeout" in diagnostics
|
||||
|
||||
def test_format_diagnostics_empty():
|
||||
"""Test that diagnostics section is empty when no errors exist."""
|
||||
nodes = [
|
||||
{
|
||||
"node": "node1",
|
||||
"status": "passing",
|
||||
"litefs_error": None
|
||||
}
|
||||
]
|
||||
diagnostics = output_formatter.format_diagnostics(nodes, use_color=False)
|
||||
assert diagnostics == ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user