mirror of
https://github.com/esphome/esphome.git
synced 2025-09-16 10:12:21 +01:00
break it out
This commit is contained in:
@@ -579,3 +579,86 @@ def test_start_web_server_with_unix_socket(tmp_path: Path) -> None:
|
|||||||
mock_server_class.assert_called_once_with(app)
|
mock_server_class.assert_called_once_with(app)
|
||||||
mock_bind.assert_called_once_with(str(socket_path), mode=0o666)
|
mock_bind.assert_called_once_with(str(socket_path), mode=0o666)
|
||||||
server.add_socket.assert_called_once()
|
server.add_socket.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
# Tests for build_cache_arguments function
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_cache_arguments_no_entry(mock_dashboard: Mock) -> None:
|
||||||
|
"""Test with no entry returns empty list."""
|
||||||
|
result = web_server.build_cache_arguments(None, mock_dashboard, 0.0)
|
||||||
|
assert result == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_cache_arguments_no_address_no_name(mock_dashboard: Mock) -> None:
|
||||||
|
"""Test with entry but no address or name."""
|
||||||
|
entry = Mock(spec=web_server.DashboardEntry)
|
||||||
|
entry.address = None
|
||||||
|
entry.name = None
|
||||||
|
result = web_server.build_cache_arguments(entry, mock_dashboard, 0.0)
|
||||||
|
assert result == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_cache_arguments_mdns_address_cached(mock_dashboard: Mock) -> None:
|
||||||
|
"""Test with .local address that has cached mDNS results."""
|
||||||
|
entry = Mock(spec=web_server.DashboardEntry)
|
||||||
|
entry.address = "device.local"
|
||||||
|
entry.name = None
|
||||||
|
mock_dashboard.mdns_status = Mock()
|
||||||
|
mock_dashboard.mdns_status.get_cached_addresses.return_value = [
|
||||||
|
"192.168.1.10",
|
||||||
|
"fe80::1",
|
||||||
|
]
|
||||||
|
|
||||||
|
result = web_server.build_cache_arguments(entry, mock_dashboard, 0.0)
|
||||||
|
|
||||||
|
assert result == [
|
||||||
|
"--mdns-address-cache",
|
||||||
|
"device.local=192.168.1.10,fe80::1",
|
||||||
|
]
|
||||||
|
mock_dashboard.mdns_status.get_cached_addresses.assert_called_once_with(
|
||||||
|
"device.local"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_cache_arguments_dns_address_cached(mock_dashboard: Mock) -> None:
|
||||||
|
"""Test with non-.local address that has cached DNS results."""
|
||||||
|
entry = Mock(spec=web_server.DashboardEntry)
|
||||||
|
entry.address = "example.com"
|
||||||
|
entry.name = None
|
||||||
|
mock_dashboard.dns_cache = Mock()
|
||||||
|
mock_dashboard.dns_cache.get_cached_addresses.return_value = [
|
||||||
|
"93.184.216.34",
|
||||||
|
"2606:2800:220:1:248:1893:25c8:1946",
|
||||||
|
]
|
||||||
|
|
||||||
|
now = 100.0
|
||||||
|
result = web_server.build_cache_arguments(entry, mock_dashboard, now)
|
||||||
|
|
||||||
|
# IPv6 addresses are sorted before IPv4
|
||||||
|
assert result == [
|
||||||
|
"--dns-address-cache",
|
||||||
|
"example.com=2606:2800:220:1:248:1893:25c8:1946,93.184.216.34",
|
||||||
|
]
|
||||||
|
mock_dashboard.dns_cache.get_cached_addresses.assert_called_once_with(
|
||||||
|
"example.com", now
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_cache_arguments_name_without_address(mock_dashboard: Mock) -> None:
|
||||||
|
"""Test with name but no address - should check mDNS with .local suffix."""
|
||||||
|
entry = Mock(spec=web_server.DashboardEntry)
|
||||||
|
entry.name = "my-device"
|
||||||
|
entry.address = None
|
||||||
|
mock_dashboard.mdns_status = Mock()
|
||||||
|
mock_dashboard.mdns_status.get_cached_addresses.return_value = ["192.168.1.20"]
|
||||||
|
|
||||||
|
result = web_server.build_cache_arguments(entry, mock_dashboard, 0.0)
|
||||||
|
|
||||||
|
assert result == [
|
||||||
|
"--mdns-address-cache",
|
||||||
|
"my-device.local=192.168.1.20",
|
||||||
|
]
|
||||||
|
mock_dashboard.mdns_status.get_cached_addresses.assert_called_once_with(
|
||||||
|
"my-device.local"
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user