1
0
Fork 0
mirror of synced 2024-12-22 06:31:07 -05:00
yadm/test/test_unit_set_local_alt_values.py

74 lines
1.9 KiB
Python
Raw Normal View History

"""Unit tests: set_local_alt_values"""
import pytest
import utils
@pytest.mark.parametrize(
2023-07-10 15:43:17 -04:00
"override",
[
False,
2023-07-10 15:43:17 -04:00
"class",
"arch",
"os",
"hostname",
"user",
"distro",
"distro-family",
2023-07-10 15:43:17 -04:00
],
ids=[
2023-07-10 15:43:17 -04:00
"no-override",
"override-class",
"override-arch",
"override-os",
"override-hostname",
"override-user",
"override-distro",
"override-distro-family",
2023-07-10 15:43:17 -04:00
],
)
@pytest.mark.usefixtures("ds1_copy")
def test_set_local_alt_values(
runner, yadm, paths, tst_arch, tst_sys, tst_host, tst_user, tst_distro, tst_distro_family, override
):
"""Test handling of local alt values"""
script = f"""
YADM_TEST=1 source {yadm} &&
set_operating_system &&
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
set_local_alt_values
echo "class='$local_class'"
echo "arch='$local_arch'"
echo "os='$local_system'"
echo "hostname='$local_host'"
echo "user='$local_user'"
echo "distro='$local_distro'"
echo "distro-family='$local_distro_family'"
"""
2023-07-10 15:43:17 -04:00
if override == "class":
utils.set_local(paths, override, "first")
utils.set_local(paths, override, "override", add=True)
elif override:
2023-07-10 15:43:17 -04:00
utils.set_local(paths, override, "override")
2023-07-10 15:43:17 -04:00
run = runner(command=["bash"], inp=script)
assert run.success
2023-07-10 15:43:17 -04:00
assert run.err == ""
default_values = {
"class": "",
"arch": tst_arch,
"os": tst_sys,
"hostname": tst_host,
"user": tst_user,
"distro": tst_distro,
"distro-family": tst_distro_family,
}
2019-10-01 09:12:18 -04:00
for key, value in default_values.items():
if key == override:
assert f"{key}='override'" in run.out
else:
assert f"{key}='{value}'" in run.out