"""Tests for SusiDNS — TDD: tests before implementation.""" import pytest from pathlib import Path from i2p_apps.susidns.manager import AddressbookManager, AddressbookEntry class TestAddressbookEntry: def test_creation(self): entry = AddressbookEntry(hostname="test.i2p", destination="AAAA" * 86) assert entry.hostname == "test.i2p" def test_str(self): entry = AddressbookEntry(hostname="test.i2p", destination="DEST") assert str(entry) == "test.i2p=DEST" class TestAddressbookManager: def test_creation(self): mgr = AddressbookManager() assert mgr is not None def test_add_entry(self): mgr = AddressbookManager() mgr.add("example.i2p", "DESTDATA") assert mgr.lookup("example.i2p") == "DESTDATA" def test_remove_entry(self): mgr = AddressbookManager() mgr.add("example.i2p", "DESTDATA") mgr.remove("example.i2p") assert mgr.lookup("example.i2p") is None def test_list_entries(self): mgr = AddressbookManager() mgr.add("a.i2p", "DEST_A") mgr.add("b.i2p", "DEST_B") entries = mgr.list_entries() assert len(entries) == 2 def test_search(self): mgr = AddressbookManager() mgr.add("alice.i2p", "DEST_A") mgr.add("bob.i2p", "DEST_B") mgr.add("alicia.i2p", "DEST_C") results = mgr.search("ali") assert len(results) == 2 def test_load_from_file(self, tmp_path: Path): hosts = tmp_path / "hosts.txt" hosts.write_text("test.i2p=DESTDATA\nother.i2p=DESTOTHER\n") mgr = AddressbookManager.from_file(hosts) assert mgr.lookup("test.i2p") == "DESTDATA" assert mgr.lookup("other.i2p") == "DESTOTHER" def test_save_to_file(self, tmp_path: Path): hosts = tmp_path / "hosts.txt" mgr = AddressbookManager() mgr.add("test.i2p", "DEST") mgr.save(hosts) content = hosts.read_text() assert "test.i2p=DEST" in content