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",
|
|
|
|
],
|
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",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.usefixtures("ds1_copy")
|
|
|
|
def test_set_local_alt_values(runner, yadm, paths, tst_arch, tst_sys, tst_host, tst_user, override):
|
2019-08-17 16:20:56 -04:00
|
|
|
"""Use issue_legacy_path_warning"""
|
|
|
|
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'"
|
|
|
|
echo "host='$local_host'"
|
|
|
|
echo "user='$local_user'"
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
if override == "class":
|
2019-08-17 16:20:56 -04:00
|
|
|
assert "class='override'" in run.out
|
|
|
|
else:
|
|
|
|
assert "class=''" in run.out
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
if override == "arch":
|
2021-12-27 16:10:13 -05:00
|
|
|
assert "arch='override'" in run.out
|
|
|
|
else:
|
|
|
|
assert f"arch='{tst_arch}'" in run.out
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
if override == "os":
|
2019-08-17 16:20:56 -04:00
|
|
|
assert "os='override'" in run.out
|
|
|
|
else:
|
|
|
|
assert f"os='{tst_sys}'" in run.out
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
if override == "hostname":
|
2020-12-21 16:38:31 -05:00
|
|
|
assert "host='override'" in run.out
|
2019-08-17 16:20:56 -04:00
|
|
|
else:
|
|
|
|
assert f"host='{tst_host}'" in run.out
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
if override == "user":
|
2020-12-21 16:38:31 -05:00
|
|
|
assert "user='override'" in run.out
|
2019-08-17 16:20:56 -04:00
|
|
|
else:
|
|
|
|
assert f"user='{tst_user}'" in run.out
|
2019-10-01 09:12:18 -04:00
|
|
|
|
|
|
|
|
2022-01-17 14:46:31 -05:00
|
|
|
def test_distro_and_family(runner, yadm):
|
|
|
|
"""Assert that local_distro/local_distro_family are set"""
|
2019-10-01 09:12:18 -04:00
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
2021-01-05 15:57:32 -05:00
|
|
|
function config() {{ echo "$1"; }}
|
2019-10-01 09:12:18 -04:00
|
|
|
function query_distro() {{ echo "testdistro"; }}
|
2022-01-17 14:46:31 -05:00
|
|
|
function query_distro_family() {{ echo "testfamily"; }}
|
2019-10-01 09:12:18 -04:00
|
|
|
set_local_alt_values
|
|
|
|
echo "distro='$local_distro'"
|
2022-01-17 14:46:31 -05:00
|
|
|
echo "distro_family='$local_distro_family'"
|
2019-10-01 09:12:18 -04:00
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-10-01 09:12:18 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2022-01-17 14:46:31 -05:00
|
|
|
assert "distro='testdistro'" in run.out
|
|
|
|
assert "distro_family='testfamily'" in run.out
|