2025-07-11 15:52:18 +00:00
|
|
|
import logging
|
2025-07-12 23:53:15 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2025-07-11 15:52:18 +00:00
|
|
|
import pytest
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from pathlib import Path
|
2025-07-12 23:53:15 +00:00
|
|
|
from yaml import CLoader as Loader
|
|
|
|
|
2025-07-11 15:52:18 +00:00
|
|
|
|
2025-07-12 23:53:15 +00:00
|
|
|
import yaml
|
2025-07-11 15:52:18 +00:00
|
|
|
from dacite import from_dict, Config, UnexpectedDataError
|
|
|
|
from enum import StrEnum
|
|
|
|
|
2025-07-12 23:53:15 +00:00
|
|
|
from amqtt.broker import BrokerContext
|
2025-07-11 15:52:18 +00:00
|
|
|
from amqtt.contexts import BrokerConfig, ListenerConfig, Dictable
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2025-07-12 23:53:15 +00:00
|
|
|
def test_entrypoint_broker_config(caplog):
|
|
|
|
test_cfg: dict[str, Any] = {
|
|
|
|
"listeners": {
|
|
|
|
"default": {"type": "tcp", "bind": "127.0.0.1:1883", "max_connections": 10},
|
|
|
|
},
|
|
|
|
'sys_interval': 1,
|
|
|
|
'auth': {
|
|
|
|
'allow_anonymous': True
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if 'plugins' not in test_cfg:
|
|
|
|
test_cfg['plugins'] = None
|
|
|
|
# cfg: dict[str, Any] = yaml.load(config, Loader=Loader)
|
2025-07-11 15:52:18 +00:00
|
|
|
|
|
|
|
|
2025-07-12 23:53:15 +00:00
|
|
|
broker_config = from_dict(data_class=BrokerConfig, data=test_cfg, config=Config(cast=[StrEnum]))
|
|
|
|
assert isinstance(broker_config, BrokerConfig)
|
2025-07-11 15:52:18 +00:00
|
|
|
|
2025-07-12 23:53:15 +00:00
|
|
|
assert broker_config.plugins is None
|
2025-07-11 15:52:18 +00:00
|
|
|
|
|
|
|
|