mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 15:42:10 +03:00
test: Add test for /etc/resolv.conf fallback
Adds a unit test `test_resolvers_unix_resolv_conf_oserror` to `tests/test_netinfo.py` to cover the `OSError` fallback logic when `/etc/resolv.conf` cannot be read in `_resolvers_unix`. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
8c99ac78b7
commit
a97443655b
1 changed files with 15 additions and 0 deletions
|
|
@ -334,3 +334,18 @@ def test_collect_local_net_no_network(mock_resolvers, mock_gw, mock_stats, mock_
|
|||
assert result.default_gateway_v6 is None
|
||||
assert result.is_dual_stack is False
|
||||
assert result.cgnat is False
|
||||
|
||||
|
||||
@patch("netsleuth.netinfo.subprocess.run")
|
||||
@patch("builtins.open")
|
||||
def test_resolvers_unix_resolv_conf_oserror(mock_open, mock_run):
|
||||
from netsleuth.netinfo import _resolvers_unix
|
||||
|
||||
mock_open.side_effect = OSError("No such file or directory")
|
||||
|
||||
mock_scutil = mock_run.return_value
|
||||
mock_scutil.stdout = ""
|
||||
|
||||
result = _resolvers_unix()
|
||||
|
||||
assert result == {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue