2018-07-11 08:50:42 -04:00
|
|
|
"""Unit tests: query_distro"""
|
2019-11-30 11:52:18 -05:00
|
|
|
import pytest
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
@pytest.mark.parametrize("condition", ["lsb_release", "os-release", "os-release-quotes", "missing"])
|
2019-11-30 11:52:18 -05:00
|
|
|
def test_query_distro(runner, yadm, tst_distro, tmp_path, condition):
|
2018-07-11 08:50:42 -04:00
|
|
|
"""Match lsb_release -si when present"""
|
2023-07-10 15:43:17 -04:00
|
|
|
test_release = "testrelease"
|
|
|
|
lsb_release = ""
|
|
|
|
os_release = tmp_path.joinpath("os-release")
|
|
|
|
if "os-release" in condition:
|
|
|
|
quotes = '"' if "quotes" in condition else ""
|
|
|
|
os_release.write_text(f"testing\nID={quotes}{test_release}{quotes}\nrelease")
|
|
|
|
if condition != "lsb_release":
|
2019-11-30 11:52:18 -05:00
|
|
|
lsb_release = 'LSB_RELEASE_PROGRAM="missing_lsb_release"'
|
2018-07-11 08:50:42 -04:00
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
2019-11-30 11:52:18 -05:00
|
|
|
{lsb_release}
|
|
|
|
OS_RELEASE="{os_release}"
|
2018-07-11 08:50:42 -04:00
|
|
|
query_distro
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
if condition == "lsb_release":
|
2019-11-30 11:52:18 -05:00
|
|
|
assert run.out.rstrip() == tst_distro
|
2023-07-10 15:43:17 -04:00
|
|
|
elif "os-release" in condition:
|
2019-11-30 11:52:18 -05:00
|
|
|
assert run.out.rstrip() == test_release
|
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.out.rstrip() == ""
|