Add management header to hosts files and enhance serialization formatting; update tests to reflect changes.
This commit is contained in:
parent
5a2e0d2623
commit
0ee720c5ef
3 changed files with 163 additions and 6 deletions
|
@ -168,7 +168,12 @@ class TestHostsParser:
|
|||
parser = HostsParser()
|
||||
content = parser.serialize(hosts_file)
|
||||
|
||||
expected = """127.0.0.1\tlocalhost
|
||||
expected = """# #
|
||||
# Host Database
|
||||
#
|
||||
# Managed by hosts - https://git.s1q.dev/phg/hosts
|
||||
# #
|
||||
127.0.0.1\tlocalhost
|
||||
192.168.1.1\trouter
|
||||
"""
|
||||
assert content == expected
|
||||
|
@ -198,6 +203,7 @@ class TestHostsParser:
|
|||
|
||||
expected = """# Header comment 1
|
||||
# Header comment 2
|
||||
# Managed by hosts - https://git.s1q.dev/phg/hosts
|
||||
127.0.0.1\tlocalhost\t# Loopback
|
||||
# 10.0.0.1\ttest
|
||||
|
||||
|
@ -211,7 +217,13 @@ class TestHostsParser:
|
|||
parser = HostsParser()
|
||||
content = parser.serialize(hosts_file)
|
||||
|
||||
assert content == "\n"
|
||||
expected = """# #
|
||||
# Host Database
|
||||
#
|
||||
# Managed by hosts - https://git.s1q.dev/phg/hosts
|
||||
# #
|
||||
"""
|
||||
assert content == expected
|
||||
|
||||
def test_write_hosts_file(self):
|
||||
"""Test writing hosts file to disk."""
|
||||
|
@ -226,7 +238,14 @@ class TestHostsParser:
|
|||
# Read back and verify
|
||||
with open(f.name, 'r') as read_file:
|
||||
content = read_file.read()
|
||||
assert content == "127.0.0.1\tlocalhost\n"
|
||||
expected = """# #
|
||||
# Host Database
|
||||
#
|
||||
# Managed by hosts - https://git.s1q.dev/phg/hosts
|
||||
# #
|
||||
127.0.0.1\tlocalhost
|
||||
"""
|
||||
assert content == expected
|
||||
|
||||
os.unlink(f.name)
|
||||
|
||||
|
@ -259,7 +278,14 @@ class TestHostsParser:
|
|||
# Check new content
|
||||
with open(f.name, 'r') as new_file:
|
||||
new_content = new_file.read()
|
||||
assert new_content == "127.0.0.1\tlocalhost\n"
|
||||
expected = """# #
|
||||
# Host Database
|
||||
#
|
||||
# Managed by hosts - https://git.s1q.dev/phg/hosts
|
||||
# #
|
||||
127.0.0.1\tlocalhost
|
||||
"""
|
||||
assert new_content == expected
|
||||
|
||||
# Cleanup
|
||||
os.unlink(backup_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue