mirror of
https://github.com/TheLocehiliosan/yadm
synced 2026-03-02 03:49:29 +00:00
Merge pull request #220
This commit is contained in:
@@ -126,7 +126,7 @@ def test_alt_conditions(
|
||||
|
||||
@pytest.mark.usefixtures('ds1_copy')
|
||||
@pytest.mark.parametrize(
|
||||
'kind', ['default', '', None, 'envtpl', 'j2cli', 'j2'])
|
||||
'kind', ['default', '', None, 'envtpl', 'j2cli', 'j2', 'esh'])
|
||||
@pytest.mark.parametrize('label', ['t', 'template', 'yadm', ])
|
||||
def test_alt_templates(
|
||||
runner, paths, kind, label):
|
||||
|
||||
@@ -112,3 +112,30 @@ def test_existing_template(runner, yadm):
|
||||
assert 'SCORES:1\n' in run.out
|
||||
assert 'TARGETS:testtgt\n' in run.out
|
||||
assert 'SOURCES:\n' in run.out
|
||||
|
||||
|
||||
def test_config_first(runner, yadm):
|
||||
"""Verify YADM_CONFIG is always processed first"""
|
||||
|
||||
config = 'yadm_config_file'
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
{INIT_VARS}
|
||||
YADM_CONFIG={config}
|
||||
record_score "1" "tgt_before" "src_before"
|
||||
record_template "tgt_tmp" "cmd_tmp" "src_tmp"
|
||||
record_score "2" "{config}" "src_config"
|
||||
record_score "3" "tgt_after" "src_after"
|
||||
{REPORT_RESULTS}
|
||||
echo "CMD_VALUE:${{alt_template_cmds[@]}}"
|
||||
echo "CMD_INDEX:${{!alt_template_cmds[@]}}"
|
||||
"""
|
||||
run = runner(command=['bash'], inp=script)
|
||||
assert run.success
|
||||
assert run.err == ''
|
||||
assert 'SIZE:3\n' in run.out
|
||||
assert 'SCORES:2 1 3\n' in run.out
|
||||
assert f'TARGETS:{config} tgt_before tgt_tmp tgt_after\n' in run.out
|
||||
assert 'SOURCES:src_config src_before src_tmp src_after\n' in run.out
|
||||
assert 'CMD_VALUE:cmd_tmp\n' in run.out
|
||||
assert 'CMD_INDEX:2\n' in run.out
|
||||
|
||||
114
test/test_unit_template_esh.py
Normal file
114
test/test_unit_template_esh.py
Normal file
@@ -0,0 +1,114 @@
|
||||
"""Unit tests: template_esh"""
|
||||
|
||||
LOCAL_CLASS = "esh_Test+@-!^Class"
|
||||
LOCAL_SYSTEM = "esh_Test+@-!^System"
|
||||
LOCAL_HOST = "esh_Test+@-!^Host"
|
||||
LOCAL_USER = "esh_Test+@-!^User"
|
||||
LOCAL_DISTRO = "esh_Test+@-!^Distro"
|
||||
TEMPLATE = f'''
|
||||
start of template
|
||||
esh class = ><%=$YADM_CLASS%><
|
||||
esh os = ><%=$YADM_OS%><
|
||||
esh host = ><%=$YADM_HOSTNAME%><
|
||||
esh user = ><%=$YADM_USER%><
|
||||
esh distro = ><%=$YADM_DISTRO%><
|
||||
<% if [ "$YADM_CLASS" = "wrongclass1" ]; then -%>
|
||||
wrong class 1
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_CLASS" = "{LOCAL_CLASS}" ]; then -%>
|
||||
Included section for class = <%=$YADM_CLASS%> (<%=$YADM_CLASS%> repeated)
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_CLASS" = "wrongclass2" ]; then -%>
|
||||
wrong class 2
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_OS" = "wrongos1" ]; then -%>
|
||||
wrong os 1
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_OS" = "{LOCAL_SYSTEM}" ]; then -%>
|
||||
Included section for os = <%=$YADM_OS%> (<%=$YADM_OS%> repeated)
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_OS" = "wrongos2" ]; then -%>
|
||||
wrong os 2
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_HOSTNAME" = "wronghost1" ]; then -%>
|
||||
wrong host 1
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_HOSTNAME" = "{LOCAL_HOST}" ]; then -%>
|
||||
Included section for host = <%=$YADM_HOSTNAME%> (<%=$YADM_HOSTNAME%> again)
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_HOSTNAME" = "wronghost2" ]; then -%>
|
||||
wrong host 2
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_USER" = "wronguser1" ]; then -%>
|
||||
wrong user 1
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_USER" = "{LOCAL_USER}" ]; then -%>
|
||||
Included section for user = <%=$YADM_USER%> (<%=$YADM_USER%> repeated)
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_USER" = "wronguser2" ]; then -%>
|
||||
wrong user 2
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_DISTRO" = "wrongdistro1" ]; then -%>
|
||||
wrong distro 1
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_DISTRO" = "{LOCAL_DISTRO}" ]; then -%>
|
||||
Included section for distro = <%=$YADM_DISTRO%> (<%=$YADM_DISTRO%> again)
|
||||
<% fi -%>
|
||||
<% if [ "$YADM_DISTRO" = "wrongdistro2" ]; then -%>
|
||||
wrong distro 2
|
||||
<% fi -%>
|
||||
end of template
|
||||
'''
|
||||
EXPECTED = f'''
|
||||
start of template
|
||||
esh class = >{LOCAL_CLASS}<
|
||||
esh os = >{LOCAL_SYSTEM}<
|
||||
esh host = >{LOCAL_HOST}<
|
||||
esh user = >{LOCAL_USER}<
|
||||
esh distro = >{LOCAL_DISTRO}<
|
||||
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
|
||||
Included section for os = {LOCAL_SYSTEM} ({LOCAL_SYSTEM} repeated)
|
||||
Included section for host = {LOCAL_HOST} ({LOCAL_HOST} again)
|
||||
Included section for user = {LOCAL_USER} ({LOCAL_USER} repeated)
|
||||
Included section for distro = {LOCAL_DISTRO} ({LOCAL_DISTRO} again)
|
||||
end of template
|
||||
'''
|
||||
|
||||
|
||||
def test_template_esh(runner, yadm, tmpdir):
|
||||
"""Test processing by esh"""
|
||||
|
||||
input_file = tmpdir.join('input')
|
||||
input_file.write(TEMPLATE, ensure=True)
|
||||
output_file = tmpdir.join('output')
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
local_class="{LOCAL_CLASS}"
|
||||
local_system="{LOCAL_SYSTEM}"
|
||||
local_host="{LOCAL_HOST}"
|
||||
local_user="{LOCAL_USER}"
|
||||
local_distro="{LOCAL_DISTRO}"
|
||||
template_esh "{input_file}" "{output_file}"
|
||||
"""
|
||||
run = runner(command=['bash'], inp=script)
|
||||
assert run.success
|
||||
assert run.err == ''
|
||||
assert output_file.read().strip() == str(EXPECTED).strip()
|
||||
|
||||
|
||||
def test_source(runner, yadm, tmpdir):
|
||||
"""Test YADM_SOURCE"""
|
||||
|
||||
input_file = tmpdir.join('input')
|
||||
input_file.write('<%= $YADM_SOURCE %>', ensure=True)
|
||||
output_file = tmpdir.join('output')
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
template_esh "{input_file}" "{output_file}"
|
||||
"""
|
||||
run = runner(command=['bash'], inp=script)
|
||||
assert run.success
|
||||
assert run.err == ''
|
||||
assert output_file.read().strip() == str(input_file)
|
||||
Reference in New Issue
Block a user