Skip to content

Commit 07e2934

Browse files
authored
Merge pull request #1394 from yedayak/interfaces-params
test(interfaces): Test for missing ip or ifconfig
2 parents 90ef9a2 + 43f294b commit 07e2934

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

test/t/unit/test_unit_compgen_available_interfaces.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from conftest import assert_bash_exec
3+
from conftest import assert_bash_exec, bash_env_saved
44

55

66
@pytest.mark.bashcomp(cmd=None)
@@ -16,10 +16,30 @@ def functions(self, bash):
1616
'_comp__test_compgen() { local -a arr=(00); _comp_compgen -v arr "$@"; _comp__test_dump; }',
1717
)
1818

19-
def test_1_trailing_colons(self, bash, functions):
19+
# We fallback to ifconfig if ip fails, so we want to check also the scenario without ip.
20+
@pytest.fixture(scope="function", params=["ip", "ifconfig"])
21+
def remove_one_tool(self, request, bash):
22+
assert_bash_exec(bash, f"{request.param}() {{ false; }}")
23+
yield
24+
assert_bash_exec(bash, f"unset -f {request.param}")
25+
26+
def test_1_trailing_colons(self, bash, functions, remove_one_tool):
2027
output = assert_bash_exec(
2128
bash,
2229
"_comp__test_compgen available_interfaces",
2330
want_output=True,
2431
)
2532
assert ":>" not in output.strip()
33+
34+
def test_2_correct_interfaces(self, bash, functions, remove_one_tool):
35+
with bash_env_saved(bash) as bash_env:
36+
# Using emulated ip and ifconfig commands
37+
bash_env.write_variable(
38+
"PATH", "$PWD/shared/bin:$PATH", quote=False
39+
)
40+
output = assert_bash_exec(
41+
bash,
42+
"_comp__test_compgen available_interfaces",
43+
want_output=True,
44+
)
45+
assert all(iface in output for iface in ["<eth0>", "<lo>"])

0 commit comments

Comments
 (0)