Skip to content

test(interfaces): Test for missing ip or ifconfig #1394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions test/t/unit/test_unit_compgen_available_interfaces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from conftest import assert_bash_exec
from conftest import assert_bash_exec, bash_env_saved


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

def test_1_trailing_colons(self, bash, functions):
# We fallback to ifconfig if ip fails, so we want to check also the scenario without ip.
@pytest.fixture(scope="function", params=["ip", "ifconfig"])
def remove_one_tool(self, request, bash):
assert_bash_exec(bash, f"{request.param}() {{ false; }}")
yield
assert_bash_exec(bash, f"unset -f {request.param}")

def test_1_trailing_colons(self, bash, functions, remove_one_tool):
output = assert_bash_exec(
bash,
"_comp__test_compgen available_interfaces",
want_output=True,
)
assert ":>" not in output.strip()

def test_2_correct_interfaces(self, bash, functions, remove_one_tool):
with bash_env_saved(bash) as bash_env:
# Using emulated ip and ifconfig commands
bash_env.write_variable(
"PATH", "$PWD/shared/bin:$PATH", quote=False
)
output = assert_bash_exec(
bash,
"_comp__test_compgen available_interfaces",
want_output=True,
)
assert all(iface in output for iface in ["<eth0>", "<lo>"])
Loading