Rename default template processor
This commit is contained in:
parent
b62a4c77a6
commit
616baaeac6
|
@ -101,7 +101,7 @@ def test_alt_conditions(
|
||||||
|
|
||||||
@pytest.mark.usefixtures('ds1_copy')
|
@pytest.mark.usefixtures('ds1_copy')
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'kind', ['builtin', '', None, 'envtpl', 'j2cli', 'j2'])
|
'kind', ['default', '', None, 'envtpl', 'j2cli', 'j2'])
|
||||||
@pytest.mark.parametrize('label', ['t', 'template', 'yadm', ])
|
@pytest.mark.parametrize('label', ['t', 'template', 'yadm', ])
|
||||||
def test_alt_templates(
|
def test_alt_templates(
|
||||||
runner, paths, kind, label):
|
runner, paths, kind, label):
|
||||||
|
@ -223,7 +223,7 @@ def test_template_overwrite_symlink(runner, yadm_y, paths, tst_sys):
|
||||||
link = paths.work.join('test_link')
|
link = paths.work.join('test_link')
|
||||||
link.mksymlinkto(target, absolute=1)
|
link.mksymlinkto(target, absolute=1)
|
||||||
|
|
||||||
template = paths.work.join('test_link##template.builtin')
|
template = paths.work.join('test_link##template.default')
|
||||||
template.write('test-data')
|
template.write('test-data')
|
||||||
|
|
||||||
run = runner(yadm_y('add', target, template))
|
run = runner(yadm_y('add', target, template))
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('label', ['', 'builtin', 'other'])
|
@pytest.mark.parametrize('label', ['', 'default', 'other'])
|
||||||
@pytest.mark.parametrize('awk', [True, False], ids=['awk', 'no-awk'])
|
@pytest.mark.parametrize('awk', [True, False], ids=['awk', 'no-awk'])
|
||||||
def test_kind_builtin(runner, yadm, awk, label):
|
def test_kind_default(runner, yadm, awk, label):
|
||||||
"""Test kind: builtin"""
|
"""Test kind: default"""
|
||||||
|
|
||||||
expected = 'template_builtin'
|
expected = 'template_default'
|
||||||
awk_avail = 'true'
|
awk_avail = 'true'
|
||||||
|
|
||||||
if not awk:
|
if not awk:
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
"""Unit tests: template_builtin"""
|
"""Unit tests: template_default"""
|
||||||
|
|
||||||
# these values are also testing the handling of bizarre characters
|
# these values are also testing the handling of bizarre characters
|
||||||
LOCAL_CLASS = "builtin_Test+@-!^Class"
|
LOCAL_CLASS = "default_Test+@-!^Class"
|
||||||
LOCAL_SYSTEM = "builtin_Test+@-!^System"
|
LOCAL_SYSTEM = "default_Test+@-!^System"
|
||||||
LOCAL_HOST = "builtin_Test+@-!^Host"
|
LOCAL_HOST = "default_Test+@-!^Host"
|
||||||
LOCAL_USER = "builtin_Test+@-!^User"
|
LOCAL_USER = "default_Test+@-!^User"
|
||||||
LOCAL_DISTRO = "builtin_Test+@-!^Distro"
|
LOCAL_DISTRO = "default_Test+@-!^Distro"
|
||||||
TEMPLATE = f'''
|
TEMPLATE = f'''
|
||||||
start of template
|
start of template
|
||||||
builtin class = >{{{{yadm.class}}}}<
|
default class = >{{{{yadm.class}}}}<
|
||||||
builtin os = >{{{{yadm.os}}}}<
|
default os = >{{{{yadm.os}}}}<
|
||||||
builtin host = >{{{{yadm.hostname}}}}<
|
default host = >{{{{yadm.hostname}}}}<
|
||||||
builtin user = >{{{{yadm.user}}}}<
|
default user = >{{{{yadm.user}}}}<
|
||||||
builtin distro = >{{{{yadm.distro}}}}<
|
default distro = >{{{{yadm.distro}}}}<
|
||||||
{{% if yadm.class == "else1" %}}
|
{{% if yadm.class == "else1" %}}
|
||||||
wrong else 1
|
wrong else 1
|
||||||
{{% else %}}
|
{{% else %}}
|
||||||
|
@ -70,11 +70,11 @@ end of template
|
||||||
'''
|
'''
|
||||||
EXPECTED = f'''
|
EXPECTED = f'''
|
||||||
start of template
|
start of template
|
||||||
builtin class = >{LOCAL_CLASS}<
|
default class = >{LOCAL_CLASS}<
|
||||||
builtin os = >{LOCAL_SYSTEM}<
|
default os = >{LOCAL_SYSTEM}<
|
||||||
builtin host = >{LOCAL_HOST}<
|
default host = >{LOCAL_HOST}<
|
||||||
builtin user = >{LOCAL_USER}<
|
default user = >{LOCAL_USER}<
|
||||||
builtin distro = >{LOCAL_DISTRO}<
|
default distro = >{LOCAL_DISTRO}<
|
||||||
Included section from else
|
Included section from else
|
||||||
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
|
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
|
||||||
Multiple lines
|
Multiple lines
|
||||||
|
@ -86,8 +86,8 @@ end of template
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def test_template_builtin(runner, yadm, tmpdir):
|
def test_template_default(runner, yadm, tmpdir):
|
||||||
"""Test template_builtin"""
|
"""Test template_default"""
|
||||||
|
|
||||||
input_file = tmpdir.join('input')
|
input_file = tmpdir.join('input')
|
||||||
input_file.write(TEMPLATE, ensure=True)
|
input_file.write(TEMPLATE, ensure=True)
|
||||||
|
@ -100,7 +100,7 @@ def test_template_builtin(runner, yadm, tmpdir):
|
||||||
local_host="{LOCAL_HOST}"
|
local_host="{LOCAL_HOST}"
|
||||||
local_user="{LOCAL_USER}"
|
local_user="{LOCAL_USER}"
|
||||||
local_distro="{LOCAL_DISTRO}"
|
local_distro="{LOCAL_DISTRO}"
|
||||||
template_builtin "{input_file}" "{output_file}"
|
template_default "{input_file}" "{output_file}"
|
||||||
"""
|
"""
|
||||||
run = runner(command=['bash'], inp=script)
|
run = runner(command=['bash'], inp=script)
|
||||||
assert run.success
|
assert run.success
|
||||||
|
@ -117,7 +117,7 @@ def test_source(runner, yadm, tmpdir):
|
||||||
|
|
||||||
script = f"""
|
script = f"""
|
||||||
YADM_TEST=1 source {yadm}
|
YADM_TEST=1 source {yadm}
|
||||||
template_builtin "{input_file}" "{output_file}"
|
template_default "{input_file}" "{output_file}"
|
||||||
"""
|
"""
|
||||||
run = runner(command=['bash'], inp=script)
|
run = runner(command=['bash'], inp=script)
|
||||||
assert run.success
|
assert run.success
|
8
yadm
8
yadm
|
@ -275,8 +275,8 @@ function record_template() {
|
||||||
function choose_template_cmd() {
|
function choose_template_cmd() {
|
||||||
kind="$1"
|
kind="$1"
|
||||||
|
|
||||||
if [ "$kind" = "builtin" ] || [ "$kind" = "" ] && awk_available; then
|
if [ "$kind" = "default" ] || [ "$kind" = "" ] && awk_available; then
|
||||||
echo "template_builtin"
|
echo "template_default"
|
||||||
elif [ "$kind" = "j2cli" ] || [ "$kind" = "j2" ] && j2cli_available; then
|
elif [ "$kind" = "j2cli" ] || [ "$kind" = "j2" ] && j2cli_available; then
|
||||||
echo "template_j2cli"
|
echo "template_j2cli"
|
||||||
elif [ "$kind" = "envtpl" ] || [ "$kind" = "j2" ] && envtpl_available; then
|
elif [ "$kind" = "envtpl" ] || [ "$kind" = "j2" ] && envtpl_available; then
|
||||||
|
@ -289,14 +289,14 @@ function choose_template_cmd() {
|
||||||
|
|
||||||
# ****** Template Processors ******
|
# ****** Template Processors ******
|
||||||
|
|
||||||
function template_builtin() {
|
function template_default() {
|
||||||
input="$1"
|
input="$1"
|
||||||
output="$2"
|
output="$2"
|
||||||
|
|
||||||
# the explicit "space + tab" character class used below is used because not
|
# the explicit "space + tab" character class used below is used because not
|
||||||
# all versions of awk seem to support the POSIX character classes [[:blank:]]
|
# all versions of awk seem to support the POSIX character classes [[:blank:]]
|
||||||
awk_pgm=$(cat << "EOF"
|
awk_pgm=$(cat << "EOF"
|
||||||
# built-in template processor
|
# built-in default template processor
|
||||||
BEGIN {
|
BEGIN {
|
||||||
blank = "[ ]"
|
blank = "[ ]"
|
||||||
c["class"] = class
|
c["class"] = class
|
||||||
|
|
Loading…
Reference in New Issue