mirror of
https://github.com/esphome/esphome.git
synced 2025-09-16 18:22:22 +01:00
fixes
This commit is contained in:
@@ -581,47 +581,3 @@ def test_address_cache_get_methods() -> None:
|
|||||||
assert cache.has_cache() is True
|
assert cache.has_cache() is True
|
||||||
empty_cache = AddressCache()
|
empty_cache = AddressCache()
|
||||||
assert empty_cache.has_cache() is False
|
assert empty_cache.has_cache() is False
|
||||||
|
|
||||||
|
|
||||||
def test_address_cache_hostname_normalization() -> None:
|
|
||||||
"""Test that hostnames are normalized for cache lookups."""
|
|
||||||
from esphome.address_cache import normalize_hostname
|
|
||||||
|
|
||||||
# Test normalize_hostname function
|
|
||||||
assert normalize_hostname("test.local") == "test.local"
|
|
||||||
assert normalize_hostname("test.local.") == "test.local"
|
|
||||||
assert normalize_hostname("TEST.LOCAL") == "test.local"
|
|
||||||
assert normalize_hostname("TeSt.LoCaL.") == "test.local"
|
|
||||||
assert normalize_hostname("example.com.") == "example.com"
|
|
||||||
|
|
||||||
# Test cache with normalized lookups
|
|
||||||
cache = AddressCache(
|
|
||||||
mdns_cache={"test.local": ["192.168.1.1"]},
|
|
||||||
dns_cache={"example.com": ["10.0.0.1"]},
|
|
||||||
)
|
|
||||||
|
|
||||||
# Should find with different case and trailing dots
|
|
||||||
assert cache.get_mdns_addresses("test.local") == ["192.168.1.1"]
|
|
||||||
assert cache.get_mdns_addresses("TEST.LOCAL") == ["192.168.1.1"]
|
|
||||||
assert cache.get_mdns_addresses("test.local.") == ["192.168.1.1"]
|
|
||||||
assert cache.get_mdns_addresses("TEST.LOCAL.") == ["192.168.1.1"]
|
|
||||||
|
|
||||||
assert cache.get_dns_addresses("example.com") == ["10.0.0.1"]
|
|
||||||
assert cache.get_dns_addresses("EXAMPLE.COM") == ["10.0.0.1"]
|
|
||||||
assert cache.get_dns_addresses("example.com.") == ["10.0.0.1"]
|
|
||||||
assert cache.get_dns_addresses("EXAMPLE.COM.") == ["10.0.0.1"]
|
|
||||||
|
|
||||||
# Test from_cli_args also normalizes
|
|
||||||
cache = AddressCache.from_cli_args(
|
|
||||||
["TEST.LOCAL.=192.168.1.1"], ["EXAMPLE.COM.=10.0.0.1"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Should store as normalized
|
|
||||||
assert "test.local" in cache.mdns_cache
|
|
||||||
assert "example.com" in cache.dns_cache
|
|
||||||
|
|
||||||
# Should find with any variation
|
|
||||||
assert cache.get_addresses("test.local") == ["192.168.1.1"]
|
|
||||||
assert cache.get_addresses("TEST.LOCAL.") == ["192.168.1.1"]
|
|
||||||
assert cache.get_addresses("example.com") == ["10.0.0.1"]
|
|
||||||
assert cache.get_addresses("EXAMPLE.COM.") == ["10.0.0.1"]
|
|
||||||
|
Reference in New Issue
Block a user