|
11 | 11 | import pytest |
12 | 12 |
|
13 | 13 | from mqttwarn.core import make_service, decode_payload |
14 | | -from tests import configfile, configfile_v2 |
| 14 | +from tests import configfile, configfile_v2, configfile_no_functions, configfile_bad_functions, \ |
| 15 | + configfile_empty_functions |
15 | 16 | from tests.util import core_bootstrap, send_message |
16 | 17 |
|
17 | 18 |
|
@@ -227,3 +228,53 @@ def test_xform_func(caplog): |
227 | 228 | # Proof that the message has been routed to the "log" plugin properly |
228 | 229 | assert "'value': 42.42" in caplog.text, caplog.text |
229 | 230 | assert "'datamap-key': 'datamap-value'" in caplog.text, caplog.text |
| 231 | + |
| 232 | + |
| 233 | +def test_config_no_functions(caplog): |
| 234 | + """ |
| 235 | + Test a configuration file which has no `functions` setting. |
| 236 | + """ |
| 237 | + |
| 238 | + with caplog.at_level(logging.DEBUG): |
| 239 | + |
| 240 | + # Bootstrap the core machinery without MQTT |
| 241 | + core_bootstrap(configfile=configfile_no_functions) |
| 242 | + |
| 243 | + # Signal mocked MQTT message to the core machinery for processing |
| 244 | + send_message(topic='test/log-1', payload='{"name": "temperature", "value": 42.42}') |
| 245 | + |
| 246 | + # Proof that the message has been routed to the "log" plugin properly |
| 247 | + assert "temperature: 42.42" in caplog.text, caplog.text |
| 248 | + |
| 249 | + |
| 250 | +def test_config_empty_functions(caplog): |
| 251 | + """ |
| 252 | + Test a configuration file which has an empty `functions` setting. |
| 253 | + """ |
| 254 | + |
| 255 | + with caplog.at_level(logging.DEBUG): |
| 256 | + |
| 257 | + # Bootstrap the core machinery without MQTT |
| 258 | + core_bootstrap(configfile=configfile_empty_functions) |
| 259 | + |
| 260 | + # Signal mocked MQTT message to the core machinery for processing |
| 261 | + send_message(topic='test/log-1', payload='{"name": "temperature", "value": 42.42}') |
| 262 | + |
| 263 | + # Proof that the message has been routed to the "log" plugin properly |
| 264 | + assert "temperature: 42.42" in caplog.text, caplog.text |
| 265 | + |
| 266 | + |
| 267 | +def test_config_bad_functions(caplog): |
| 268 | + """ |
| 269 | + Test a configuration file which has no `functions` setting. |
| 270 | + """ |
| 271 | + |
| 272 | + with caplog.at_level(logging.DEBUG): |
| 273 | + |
| 274 | + # Bootstrapping the machinery with invalid path to functions file should croak. |
| 275 | + with pytest.raises(OSError) as excinfo: |
| 276 | + core_bootstrap(configfile=configfile_bad_functions) |
| 277 | + |
| 278 | + error_message = str(excinfo.value) |
| 279 | + assert "UNKNOWN FILE REFERENCE" in error_message |
| 280 | + assert "not found" in error_message |
0 commit comments