30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
|
|
"""Tests for reverse-pointer naming and hosts-file block management."""
|
||
|
|
from mdns_tools import reverse as rv
|
||
|
|
from mdns_tools import hosts as h
|
||
|
|
|
||
|
|
|
||
|
|
def test_reverse_name_ipv4():
|
||
|
|
arpa, fam = rv._reverse_name("192.168.1.17")
|
||
|
|
assert arpa == "17.1.168.192.in-addr.arpa"
|
||
|
|
assert fam == "v4"
|
||
|
|
|
||
|
|
|
||
|
|
def test_reverse_name_ipv6_family():
|
||
|
|
_, fam = rv._reverse_name("2800:e2::5")
|
||
|
|
assert fam == "v6"
|
||
|
|
|
||
|
|
|
||
|
|
def test_hosts_block_render_and_strip_roundtrip():
|
||
|
|
mapping = {"dell.local": "192.168.1.17", "hp62a.local": "192.168.1.16"}
|
||
|
|
block = h._render_block(mapping)
|
||
|
|
assert h.MARK_BEGIN in block and h.MARK_END in block
|
||
|
|
assert "192.168.1.17\tdell.local dell" in block
|
||
|
|
# A file with the block should strip back to just its original body.
|
||
|
|
original = "127.0.0.1\tlocalhost\n" + block + "\n"
|
||
|
|
assert h._strip_block(original).strip() == "127.0.0.1\tlocalhost"
|
||
|
|
|
||
|
|
|
||
|
|
def test_hosts_strip_preserves_unmanaged_lines():
|
||
|
|
text = "1.2.3.4\tkeep.me\n" + h.MARK_BEGIN + "\n9.9.9.9\tgone\n" + h.MARK_END
|
||
|
|
assert h._strip_block(text).strip() == "1.2.3.4\tkeep.me"
|