40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
from ais_hub.config import Config, load_config
|
|
|
|
|
|
def test_defaults_when_no_file():
|
|
cfg = load_config(None)
|
|
assert isinstance(cfg, Config)
|
|
assert cfg.ingest.ais_udp.port == 4001
|
|
assert cfg.publish.udp_tx_outbox.port == 6010
|
|
assert cfg.publish.udp_nmea.port == 6007
|
|
assert cfg.publish.udp_events.port == 7001
|
|
|
|
|
|
def test_yaml_overrides(tmp_path: Path):
|
|
p = tmp_path / "c.yaml"
|
|
p.write_text(
|
|
"ingest:\n"
|
|
" ais_udp:\n"
|
|
" port: 5555\n"
|
|
"publish:\n"
|
|
" http:\n"
|
|
" port: 9090\n",
|
|
encoding="utf-8",
|
|
)
|
|
cfg = load_config(p)
|
|
assert cfg.ingest.ais_udp.port == 5555
|
|
assert cfg.publish.http.port == 9090
|
|
# Untouched defaults remain.
|
|
assert cfg.publish.udp_nmea.port == 6007
|
|
|
|
|
|
def test_env_overrides(tmp_path: Path, monkeypatch):
|
|
monkeypatch.setenv("AIS_HUB_PUBLISH__HTTP__PORT", "7070")
|
|
monkeypatch.setenv("AIS_HUB_STORAGE__STORE_RAW_NMEA", "true")
|
|
cfg = load_config(None)
|
|
assert cfg.publish.http.port == 7070
|
|
assert cfg.storage.store_raw_nmea is True
|