Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uc9V1v7iXruubpoLiSE24M
27 lines
902 B
Python
27 lines
902 B
Python
import asyncio
|
|
|
|
from hbd.client import connectivity
|
|
from hbd.client.plugins.network_monitor import NetworkMonitorPlugin
|
|
|
|
|
|
class _FakeShared:
|
|
def as_metric(self):
|
|
return {"ipv4": {"present": True, "addr": "192.0.2.5", "gateway": "192.0.2.1", "rtt": 9.0},
|
|
"ipv6": {"present": False, "addr": None, "gateway": None, "rtt": None}}
|
|
|
|
|
|
def test_collect_includes_connectivity_when_probe_running():
|
|
connectivity.set_shared(_FakeShared())
|
|
try:
|
|
data = asyncio.run(NetworkMonitorPlugin()._collect_metrics())
|
|
finally:
|
|
connectivity.set_shared(None)
|
|
assert data["connectivity"]["ipv4"]["present"] is True
|
|
assert data["connectivity"]["ipv6"]["present"] is False
|
|
|
|
|
|
def test_collect_omits_connectivity_without_probe():
|
|
connectivity.set_shared(None)
|
|
data = asyncio.run(NetworkMonitorPlugin()._collect_metrics())
|
|
assert "connectivity" not in data
|