83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
import pytest
|
|
import output_formatter
|
|
|
|
def test_format_cluster_summary():
|
|
"""Test the summary string generation."""
|
|
cluster_data = {
|
|
"health": "Healthy",
|
|
"primary_count": 1,
|
|
"nodes": [],
|
|
"nomad_available": False
|
|
}
|
|
summary = output_formatter.format_summary(cluster_data)
|
|
assert "Healthy" in summary
|
|
assert "Primaries" in summary
|
|
assert "WARNING: Nomad CLI unavailable" in summary
|
|
|
|
def test_format_node_table():
|
|
"""Test the table generation."""
|
|
nodes = [
|
|
{
|
|
"node": "node1",
|
|
"role": "primary",
|
|
"status": "passing",
|
|
"candidate": True,
|
|
"uptime": "1h",
|
|
"replication_lag": "N/A",
|
|
"litefs_primary": True,
|
|
"dbs": {"db1": {"txid": "1", "checksum": "abc"}}
|
|
}
|
|
]
|
|
table = output_formatter.format_node_table(nodes, use_color=False)
|
|
assert "node1" in table
|
|
assert "primary" in table
|
|
assert "passing" in table
|
|
assert "db1" in table
|
|
assert "Cand" 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
|
|
},
|
|
{
|
|
"node": "node2",
|
|
"status": "standby", # Should also be empty
|
|
"litefs_error": None
|
|
}
|
|
]
|
|
diagnostics = output_formatter.format_diagnostics(nodes, use_color=False)
|
|
assert diagnostics == ""
|
|
|
|
def test_format_node_table_status_colors():
|
|
"""Test that different statuses are handled."""
|
|
nodes = [
|
|
{"node": "n1", "role": "primary", "status": "passing", "litefs_primary": True},
|
|
{"node": "n2", "role": "replica", "status": "standby", "litefs_primary": False},
|
|
{"node": "n3", "role": "primary", "status": "unregistered", "litefs_primary": True},
|
|
]
|
|
table = output_formatter.format_node_table(nodes, use_color=False)
|
|
assert "passing" in table
|
|
assert "standby" in table
|
|
assert "unregistered" in table
|
|
|