2022-01-17 14:46:31 -05:00
|
|
|
"""Unit tests: query_distro_family"""
|
2024-11-11 16:30:41 -05:00
|
|
|
|
2022-01-17 14:46:31 -05:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2024-12-09 17:10:35 -05:00
|
|
|
@pytest.mark.parametrize("condition", ["os-release", "os-release-quotes", "missing", "fallback"])
|
2022-01-17 14:46:31 -05:00
|
|
|
def test_query_distro_family(runner, yadm, tmp_path, condition):
|
|
|
|
"""Match ID_LIKE when present"""
|
2023-07-10 15:43:17 -04:00
|
|
|
test_family = "testfamily"
|
|
|
|
os_release = tmp_path.joinpath("os-release")
|
|
|
|
if "os-release" in condition:
|
|
|
|
quotes = '"' if "quotes" in condition else ""
|
2024-12-09 17:10:35 -05:00
|
|
|
os_release.write_text(f"testing\nID=test\nID_LIKE={quotes}{test_family}{quotes}\nfamily")
|
|
|
|
elif condition == "fallback":
|
|
|
|
os_release.write_text(f'testing\nID="{test_family}"\nfamily')
|
2022-01-17 14:46:31 -05:00
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
OS_RELEASE="{os_release}"
|
|
|
|
query_distro_family
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2022-01-17 14:46:31 -05:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2024-12-09 17:10:35 -05:00
|
|
|
if condition == "missing":
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.out.rstrip() == ""
|
2024-12-09 17:10:35 -05:00
|
|
|
else:
|
|
|
|
assert run.out.rstrip() == test_family
|