Files
heartbeat/tests/test_proto.py
T
2026-02-08 16:05:03 -05:00

25 lines
703 B
Python

from hbd.proto import dicttos, stodict, oldmtodict
def test_dicttos_and_stodict_uncompressed():
msg = dicttos("HTB", {"name": "host.example", "interval": 10})
d = stodict(msg)
assert d["ID"].startswith("HTB")
assert d["name"] == "host.example"
assert d["interval"] == 10
def test_dicttos_and_stodict_compressed():
msg = dicttos("ACK", {"time": 12345}, compress=True)
d = stodict(msg)
# for compressed the original code included the colon in ID slice; ensure no crash
assert "ID" in d
def test_oldmtodict():
msg = b"name=foo;interval=5"
d = oldmtodict(msg)
assert d["ID"].startswith("HTB")
assert d["name"] == "foo"
assert d["interval"] == 5