2019-08-17 16:20:56 -04:00
|
|
|
"""Unit tests: set_local_alt_values"""
|
2024-11-11 16:30:41 -05:00
|
|
|
|
2019-08-17 16:20:56 -04:00
|
|
|
import pytest
|
|
|
|
import utils
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 15:43:17 -04:00
|
|
|
"override",
|
|
|
|
[
|
2019-08-17 16:20:56 -04:00
|
|
|
False,
|
2023-07-10 15:43:17 -04:00
|
|
|
"class",
|
|
|
|
"arch",
|
|
|
|
"os",
|
|
|
|
"hostname",
|
|
|
|
"user",
|
2024-12-10 12:35:26 -05:00
|
|
|
"distro",
|
|
|
|
"distro-family",
|
2023-07-10 15:43:17 -04:00
|
|
|
],
|
2019-08-17 16:20:56 -04:00
|
|
|
ids=[
|
2023-07-10 15:43:17 -04:00
|
|
|
"no-override",
|
|
|
|
"override-class",
|
|
|
|
"override-arch",
|
|
|
|
"override-os",
|
|
|
|
"override-hostname",
|
|
|
|
"override-user",
|
2024-12-10 12:35:26 -05:00
|
|
|
"override-distro",
|
|
|
|
"override-distro-family",
|
2023-07-10 15:43:17 -04:00
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.usefixtures("ds1_copy")
|
2024-12-10 12:35:26 -05:00
|
|
|
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"""
|
2019-08-17 16:20:56 -04:00
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm} &&
|
|
|
|
set_operating_system &&
|
2020-11-17 15:57:34 -05:00
|
|
|
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
|
2019-08-17 16:20:56 -04:00
|
|
|
set_local_alt_values
|
|
|
|
echo "class='$local_class'"
|
2021-12-27 16:10:13 -05:00
|
|
|
echo "arch='$local_arch'"
|
2019-08-17 16:20:56 -04:00
|
|
|
echo "os='$local_system'"
|
2024-12-10 12:35:26 -05:00
|
|
|
echo "hostname='$local_host'"
|
2019-08-17 16:20:56 -04:00
|
|
|
echo "user='$local_user'"
|
2024-12-10 12:35:26 -05:00
|
|
|
echo "distro='$local_distro'"
|
|
|
|
echo "distro-family='$local_distro_family'"
|
2019-08-17 16:20:56 -04:00
|
|
|
"""
|
|
|
|
|
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)
|
2021-01-10 16:38:42 -05:00
|
|
|
elif override:
|
2023-07-10 15:43:17 -04:00
|
|
|
utils.set_local(paths, override, "override")
|
2019-08-17 16:20:56 -04:00
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-08-17 16:20:56 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2019-08-17 16:20:56 -04:00
|
|
|
|
2024-12-10 12:35:26 -05:00
|
|
|
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
|
|
|
|
2024-12-10 12:35:26 -05: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
|