57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
from pathlib import Path
|
|
|
|
|
|
def test_parse_icdb_server_address_extracts_port_and_hosts(tmp_path):
|
|
from cbb_refresh_verify.mentor_adapter import parse_icdb_server_address
|
|
|
|
address = tmp_path / "sAddress.adr"
|
|
address.write_text(
|
|
"guid\n127.0.0.1\n192.168.1.10\n10062\n1094\n"
|
|
"vt40T8RtWJOG2cE2Nlvc5A\n535943\n",
|
|
encoding="ascii",
|
|
)
|
|
|
|
assert parse_icdb_server_address(address) == {
|
|
"port": 10062,
|
|
"hosts": ["127.0.0.1", "192.168.1.10"],
|
|
}
|
|
|
|
|
|
def test_unreachable_icdb_address_is_preserved(tmp_path, monkeypatch):
|
|
from cbb_refresh_verify import mentor_adapter
|
|
|
|
database = tmp_path / "database"
|
|
address = database / "cdbsvr" / "sAddress.adr"
|
|
address.parent.mkdir(parents=True)
|
|
address.write_text("guid\n127.0.0.1\n10062\n1094\n", encoding="ascii")
|
|
monkeypatch.setattr(mentor_adapter, "probe_icdb_server", lambda hosts, port: (False, "10062 unreachable"))
|
|
events = []
|
|
|
|
result = mentor_adapter.prepare_icdb_address(
|
|
database,
|
|
tmp_path / "evidence",
|
|
emit=lambda **event: events.append(event),
|
|
)
|
|
|
|
assert result["status"] == "UNREACHABLE"
|
|
assert address.exists()
|
|
moved = list((tmp_path / "evidence" / "diagnostics" / "cdbsvr").glob("sAddress.adr.stale-*"))
|
|
assert len(moved) == 0
|
|
assert address.read_text(encoding="ascii") == "guid\n127.0.0.1\n10062\n1094\n"
|
|
assert events[-1]["stage"] == "icdb_address_check"
|
|
|
|
|
|
def test_live_icdb_address_is_left_in_place(tmp_path, monkeypatch):
|
|
from cbb_refresh_verify import mentor_adapter
|
|
|
|
database = tmp_path / "database"
|
|
address = database / "cdbsvr" / "sAddress.adr"
|
|
address.parent.mkdir(parents=True)
|
|
address.write_text("guid\n127.0.0.1\n10062\n1094\n", encoding="ascii")
|
|
monkeypatch.setattr(mentor_adapter, "probe_icdb_server", lambda hosts, port: (True, "127.0.0.1:10062"))
|
|
|
|
result = mentor_adapter.prepare_icdb_address(database, tmp_path / "evidence")
|
|
|
|
assert result["status"] == "LIVE"
|
|
assert address.is_file()
|