diff --git a/tests/plugins/host_agent/test_agent_build_payload.py b/tests/plugins/host_agent/test_agent_build_payload.py index 2d7f26a..6e03452 100644 --- a/tests/plugins/host_agent/test_agent_build_payload.py +++ b/tests/plugins/host_agent/test_agent_build_payload.py @@ -9,14 +9,19 @@ def test_build_sample_shape(): fake_load = {"1m": 0.1, "5m": 0.2, "15m": 0.3} fake_storage = [{"mount": "/", "total_bytes": 1000, "used_bytes": 400}] - with patch.object(a, "collect_cpu", return_value=12.5), \ + with patch.object(a, "collect_cpu", return_value=(12.5, [12.0, 13.0])), \ patch.object(a, "collect_memory", return_value=fake_mem), \ patch.object(a, "collect_load", return_value=fake_load), \ patch.object(a, "collect_uptime", return_value=1234), \ - patch.object(a, "collect_storage", return_value=fake_storage): - sample = a.build_sample(mounts=["/"]) + patch.object(a, "collect_storage", return_value=fake_storage), \ + patch.object(a, "collect_temps", return_value=[]), \ + patch.object(a, "collect_psi", return_value={}), \ + patch.object(a, "collect_net_raw", return_value={}), \ + patch.object(a, "collect_diskio_raw", return_value={}): + sample = a.build_sample(["/"], {}) assert sample["cpu_pct"] == 12.5 + assert sample["cpu_cores"] == [12.0, 13.0] assert sample["mem"]["used_bytes"] == 40 assert sample["load"]["1m"] == 0.1 assert sample["uptime_secs"] == 1234 @@ -36,8 +41,12 @@ def test_build_sample_tolerates_collector_failure(): "available_bytes": 1, "swap_used_bytes": 0}), \ patch.object(a, "collect_load", return_value={"1m": 0.0, "5m": 0.0, "15m": 0.0}), \ patch.object(a, "collect_uptime", return_value=0), \ - patch.object(a, "collect_storage", return_value=[]): - sample = a.build_sample(mounts=["/"]) + patch.object(a, "collect_storage", return_value=[]), \ + patch.object(a, "collect_temps", return_value=[]), \ + patch.object(a, "collect_psi", return_value={}), \ + patch.object(a, "collect_net_raw", return_value={}), \ + patch.object(a, "collect_diskio_raw", return_value={}): + sample = a.build_sample(["/"], {}) assert sample["cpu_pct"] is None assert sample["mem"]["total_bytes"] == 1 diff --git a/tests/plugins/host_agent/test_agent_collectors.py b/tests/plugins/host_agent/test_agent_collectors.py index 9f3d1fa..44aa775 100644 --- a/tests/plugins/host_agent/test_agent_collectors.py +++ b/tests/plugins/host_agent/test_agent_collectors.py @@ -56,10 +56,11 @@ def test_collect_cpu_reads_twice(): with patch.object(a, "_read_file", _read), \ patch.object(a.time, "sleep", lambda _s: None): - pct = a.collect_cpu(sample_window=0.0) + pct, cores = a.collect_cpu(sample_window=0.0) # totals: 1000 → 2000 (delta 1000). idle+iowait: 850 → 1700 (delta 850). - # busy = 150. pct = 15.0. + # busy = 150. pct = 15.0. No cpuN lines in the fixture → no per-core values. assert pct == pytest.approx(15.0, abs=0.1) + assert cores == [] def test_collect_storage():