|
4 | 4 |
|
5 | 5 | import asyncio |
6 | 6 |
|
| 7 | +import netifaces |
| 8 | + |
7 | 9 | from tests.module_factory import ModuleFactory |
8 | 10 | import maxminddb |
9 | 11 | import pytest |
@@ -405,27 +407,28 @@ async def test_shutdown_gracefully( |
405 | 407 |
|
406 | 408 |
|
407 | 409 | @pytest.mark.parametrize( |
408 | | - "platform_system, subprocess_output, expected_ip", |
| 410 | + "is_running_non_stop, netifaces_ret, expected_return_value", |
409 | 411 | [ |
410 | | - # Testcase 1: MacOS (Darwin) with valid output |
411 | | - ("Darwin", b"gateway: 192.168.1.1", "192.168.1.1"), |
412 | | - # Testcase 2: Linux with valid output |
413 | | - ("Linux", b"default via 10.0.0.1 dev eth0", "10.0.0.1"), |
414 | | - # Testcase 3: MacOS with invalid output |
415 | | - ("Darwin", b"No default gateway", False), |
416 | | - # Testcase 4: Unsupported OS |
417 | | - ("Windows", b"", False), |
| 412 | + ( |
| 413 | + True, |
| 414 | + {"default": {netifaces.AF_INET: ["192.168.1.1"]}}, |
| 415 | + "192.168.1.1", |
| 416 | + ), |
| 417 | + (True, {}, False), |
| 418 | + (True, {"default": {}}, False), |
| 419 | + (True, {"default": {netifaces.AF_INET: []}}, False), |
| 420 | + (False, "192.168.1.1", False), |
418 | 421 | ], |
419 | 422 | ) |
420 | 423 | def test_get_gateway_ip( |
421 | | - mocker, platform_system, subprocess_output, expected_ip |
| 424 | + mocker, is_running_non_stop, netifaces_ret, expected_return_value |
422 | 425 | ): |
423 | 426 | ip_info = ModuleFactory().create_ip_info_obj() |
424 | | - mocker.patch("platform.system", return_value=platform_system) |
425 | | - mocker.patch("subprocess.check_output", return_value=subprocess_output) |
426 | | - mocker.patch("sys.argv", ["-i", "eth0"]) |
| 427 | + ip_info.is_running_non_stop = is_running_non_stop |
| 428 | + mocker.patch("netifaces.gateways", return_value=netifaces_ret) |
| 429 | + |
427 | 430 | result = ip_info.get_gateway_ip_if_interface() |
428 | | - assert result == expected_ip |
| 431 | + assert result == expected_return_value |
429 | 432 |
|
430 | 433 |
|
431 | 434 | @pytest.mark.parametrize( |
|
0 commit comments