|
251 | 251 | "time_since_update": 1.55433297157288, |
252 | 252 | "tx": 0, |
253 | 253 | }, |
254 | | - { |
255 | | - "bytes_sent": 1070106, |
256 | | - "bytes_recv": 163781155, |
257 | | - "speed": 1048576000, |
258 | | - "key": "interface_name", |
259 | | - "interface_name": "eth0_v4", |
260 | | - "bytes_all": 164851261, |
261 | | - "time_since_update": 25.680001497268677, |
262 | | - "bytes_recv_gauge": 5939087689, |
263 | | - "bytes_recv_rate_per_sec": 6377770.0, |
264 | | - "bytes_sent_gauge": 82538934, |
265 | | - "bytes_sent_rate_per_sec": 41670.0, |
266 | | - "bytes_all_gauge": 6021626623, |
267 | | - "bytes_all_rate_per_sec": 6419441.0, |
268 | | - }, |
269 | 254 | ], |
270 | 255 | "sensors": [ |
271 | 256 | { |
|
307 | 292 | "eth0": {"is_up": True, "rx": 3953, "tx": 5995, "speed": 9.8}, |
308 | 293 | "tunl0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0}, |
309 | 294 | "sit0": {"is_up": False, "rx": 0.0, "tx": 0.0, "speed": 0.0}, |
310 | | - "eth0_v4": {"is_up": None, "rx": 6377770.0, "speed": 1.0, "tx": 41670.0}, |
311 | 295 | }, |
312 | 296 | "docker": {"docker_active": 2, "docker_cpu_use": 77.2, "docker_memory_use": 1149.6}, |
313 | 297 | "uptime": "3 days, 10:25:20", |
|
332 | 316 | }, |
333 | 317 | } |
334 | 318 |
|
| 319 | +RESPONSE_V4: dict[str, Any] = { |
| 320 | + "containers": [ |
| 321 | + { |
| 322 | + "key": "name", |
| 323 | + "name": "container1", |
| 324 | + "id": "1234", |
| 325 | + "status": "running", |
| 326 | + "created": "2024-06-07T09:21:57.688106748Z", |
| 327 | + "command": "./command", |
| 328 | + "image": ["image1/latest"], |
| 329 | + "io": {}, |
| 330 | + "memory": {}, |
| 331 | + "network": {}, |
| 332 | + "cpu": {"total": 0.37484029484029485}, |
| 333 | + "cpu_percent": 0.37484029484029485, |
| 334 | + "memory_usage": None, |
| 335 | + "uptime": "28 secs", |
| 336 | + "engine": "docker", |
| 337 | + }, |
| 338 | + { |
| 339 | + "key": "name", |
| 340 | + "name": "container2", |
| 341 | + "id": "5678", |
| 342 | + "status": "running", |
| 343 | + "created": "2023-08-23T21:54:50.745112185Z", |
| 344 | + "command": "./command", |
| 345 | + "image": ["image2:latest"], |
| 346 | + "io": {"cumulative_ior": 36413440, "cumulative_iow": 0}, |
| 347 | + "memory": {}, |
| 348 | + "network": {"cumulative_rx": 12012442, "cumulative_tx": 45791653}, |
| 349 | + "cpu": {"total": 0.0}, |
| 350 | + "cpu_percent": 0.0, |
| 351 | + "memory_usage": None, |
| 352 | + "uptime": "3 days", |
| 353 | + "engine": "docker", |
| 354 | + }, |
| 355 | + ], |
| 356 | + "network": [ |
| 357 | + { |
| 358 | + "bytes_sent": 1070106, |
| 359 | + "bytes_recv": 163781155, |
| 360 | + "speed": 1048576000, |
| 361 | + "key": "interface_name", |
| 362 | + "interface_name": "eth0", |
| 363 | + "bytes_all": 164851261, |
| 364 | + "time_since_update": 25.680001497268677, |
| 365 | + "bytes_recv_gauge": 5939087689, |
| 366 | + "bytes_recv_rate_per_sec": 6377770.0, |
| 367 | + "bytes_sent_gauge": 82538934, |
| 368 | + "bytes_sent_rate_per_sec": 41670.0, |
| 369 | + "bytes_all_gauge": 6021626623, |
| 370 | + "bytes_all_rate_per_sec": 6419441.0, |
| 371 | + }, |
| 372 | + ], |
| 373 | +} |
| 374 | + |
| 375 | +HA_SENSOR_DATA_V4: dict[str, Any] = { |
| 376 | + "docker": {"docker_active": 2, "docker_cpu_use": 0.4, "docker_memory_use": 0.0}, |
| 377 | + "network": { |
| 378 | + "eth0": {"is_up": None, "rx": 6377770.0, "speed": 1.0, "tx": 41670.0}, |
| 379 | + }, |
| 380 | +} |
| 381 | + |
335 | 382 |
|
336 | 383 | @pytest.mark.asyncio |
337 | 384 | async def test_non_existing_endpoint(httpx_mock: HTTPXMock) -> None: |
@@ -369,14 +416,20 @@ async def test_exisiting_endpoint(httpx_mock: HTTPXMock) -> None: |
369 | 416 |
|
370 | 417 |
|
371 | 418 | @pytest.mark.asyncio |
372 | | -async def test_ha_sensor_data(httpx_mock: HTTPXMock) -> None: |
| 419 | +@pytest.mark.parametrize( |
| 420 | + ("version", "response", "expected"), |
| 421 | + [(3, RESPONSE, HA_SENSOR_DATA), (4, RESPONSE_V4, HA_SENSOR_DATA_V4)], |
| 422 | +) |
| 423 | +async def test_ha_sensor_data( |
| 424 | + httpx_mock: HTTPXMock, version: int, response: dict, expected: dict |
| 425 | +) -> None: |
373 | 426 | """Test the return value for ha sensors.""" |
374 | | - httpx_mock.add_response(json=RESPONSE) |
| 427 | + httpx_mock.add_response(json=response) |
375 | 428 |
|
376 | | - client = Glances() |
| 429 | + client = Glances(version=version) |
377 | 430 | result = await client.get_ha_sensor_data() |
378 | 431 |
|
379 | | - assert result == HA_SENSOR_DATA |
| 432 | + assert result == expected |
380 | 433 |
|
381 | 434 |
|
382 | 435 | @pytest.mark.asyncio |
|
0 commit comments