mirror of
https://github.com/kc1awv/rrcd.git
synced 2026-07-10 02:28:11 -07:00
enforce fixed hub destination namespace
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from rrcd.cli import _build_arg_parser, _write_default_config
|
||||
from rrcd.constants import HUB_DEST_NAME
|
||||
|
||||
|
||||
def test_arg_parser_rejects_dest_name_override() -> None:
|
||||
parser = _build_arg_parser()
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
parser.parse_args(["--dest-name", "custom.hub"])
|
||||
|
||||
|
||||
def test_default_config_does_not_emit_dest_name_field(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "rrcd.toml"
|
||||
identity_path = tmp_path / "hub_identity"
|
||||
|
||||
_write_default_config(str(config_path), str(identity_path))
|
||||
|
||||
content = config_path.read_text(encoding="utf-8")
|
||||
assert "dest_name =" not in content
|
||||
assert f"Hubs always announce on {HUB_DEST_NAME!r}." in content
|
||||
@@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from rrcd.config import ConfigManager, HubRuntimeConfig
|
||||
from rrcd.constants import HUB_DEST_NAME
|
||||
from rrcd.service import HubService
|
||||
|
||||
|
||||
class _FakeHub:
|
||||
def __init__(self) -> None:
|
||||
self.log = logging.getLogger("test")
|
||||
self.config = HubRuntimeConfig()
|
||||
|
||||
|
||||
def test_apply_config_data_ignores_dest_name_override() -> None:
|
||||
manager = ConfigManager(_FakeHub())
|
||||
base = HubRuntimeConfig()
|
||||
|
||||
updated = manager.apply_config_data(
|
||||
base,
|
||||
{
|
||||
"dest_name": "custom.hub",
|
||||
"hub": {"dest_name": "custom.hub"},
|
||||
"hub_name": "custom-name",
|
||||
},
|
||||
)
|
||||
|
||||
assert updated.dest_name == HUB_DEST_NAME
|
||||
assert updated.hub_name == "custom-name"
|
||||
|
||||
|
||||
def test_service_normalizes_custom_dest_name() -> None:
|
||||
service = HubService(HubRuntimeConfig(dest_name="custom.hub"))
|
||||
|
||||
assert service.config.dest_name == HUB_DEST_NAME
|
||||
Reference in New Issue
Block a user