2019-08-17 20:20:56 +00:00
|
|
|
"""Unit tests: set_local_alt_values"""
|
|
|
|
import pytest
|
|
|
|
import utils
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'override', [
|
|
|
|
False,
|
|
|
|
'class',
|
|
|
|
'os',
|
|
|
|
'hostname',
|
|
|
|
'user',
|
|
|
|
],
|
|
|
|
ids=[
|
|
|
|
'no-override',
|
|
|
|
'override-class',
|
|
|
|
'override-os',
|
|
|
|
'override-hostname',
|
|
|
|
'override-user',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@pytest.mark.usefixtures('ds1_copy')
|
|
|
|
def test_set_local_alt_values(
|
|
|
|
runner, yadm, paths, tst_sys, tst_host, tst_user, override):
|
|
|
|
"""Use issue_legacy_path_warning"""
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm} &&
|
|
|
|
set_operating_system &&
|
2020-11-17 20:57:34 +00:00
|
|
|
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
|
2019-08-17 20:20:56 +00:00
|
|
|
set_local_alt_values
|
|
|
|
echo "class='$local_class'"
|
|
|
|
echo "os='$local_system'"
|
|
|
|
echo "host='$local_host'"
|
|
|
|
echo "user='$local_user'"
|
|
|
|
"""
|
|
|
|
|
|
|
|
if override:
|
|
|
|
utils.set_local(paths, override, 'override')
|
|
|
|
|
|
|
|
run = runner(command=['bash'], inp=script)
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
|
|
|
|
if override == 'class':
|
|
|
|
assert "class='override'" in run.out
|
|
|
|
else:
|
|
|
|
assert "class=''" in run.out
|
|
|
|
|
|
|
|
if override == 'os':
|
|
|
|
assert "os='override'" in run.out
|
|
|
|
else:
|
|
|
|
assert f"os='{tst_sys}'" in run.out
|
|
|
|
|
|
|
|
if override == 'hostname':
|
2020-12-21 21:38:31 +00:00
|
|
|
assert "host='override'" in run.out
|
2019-08-17 20:20:56 +00:00
|
|
|
else:
|
|
|
|
assert f"host='{tst_host}'" in run.out
|
|
|
|
|
|
|
|
if override == 'user':
|
2020-12-21 21:38:31 +00:00
|
|
|
assert "user='override'" in run.out
|
2019-08-17 20:20:56 +00:00
|
|
|
else:
|
|
|
|
assert f"user='{tst_user}'" in run.out
|
2019-10-01 13:12:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_distro(runner, yadm):
|
|
|
|
"""Assert that local_distro is set"""
|
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
2021-01-05 20:57:32 +00:00
|
|
|
function config() {{ echo "$1"; }}
|
2019-10-01 13:12:18 +00:00
|
|
|
function query_distro() {{ echo "testdistro"; }}
|
|
|
|
set_local_alt_values
|
|
|
|
echo "distro='$local_distro'"
|
|
|
|
"""
|
|
|
|
run = runner(command=['bash'], inp=script)
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ''
|
|
|
|
assert run.out.strip() == "distro='testdistro'"
|