1
0
Fork 0
mirror of synced 2024-11-05 01:08:59 -05:00
yadm/test/test_unit_record_template.py

56 lines
1.5 KiB
Python
Raw Normal View History

2019-10-01 09:12:18 -04:00
"""Unit tests: record_template"""
INIT_VARS = """
alt_targets=()
alt_template_cmds=()
alt_sources=()
2019-10-01 09:12:18 -04:00
"""
REPORT_RESULTS = """
echo "SIZE:${#alt_targets[@]}"
echo "TARGETS:${alt_targets[@]}"
2019-10-01 09:12:18 -04:00
echo "CMDS:${alt_template_cmds[@]}"
echo "SOURCES:${alt_sources[@]}"
2019-10-01 09:12:18 -04:00
"""
def test_new_template(runner, yadm):
"""Test new template"""
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
record_template "tgt_one" "cmd_one" "src_one"
record_template "tgt_two" "cmd_two" "src_two"
record_template "tgt_three" "cmd_three" "src_three"
2019-10-01 09:12:18 -04:00
{REPORT_RESULTS}
"""
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 == ""
assert "SIZE:3\n" in run.out
assert "TARGETS:tgt_one tgt_two tgt_three\n" in run.out
assert "CMDS:cmd_one cmd_two cmd_three\n" in run.out
assert "SOURCES:src_one src_two src_three\n" in run.out
2019-10-01 09:12:18 -04:00
def test_existing_template(runner, yadm):
"""Overwrite existing templates"""
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
alt_targets=("testtgt")
2019-10-01 09:12:18 -04:00
alt_template_cmds=("existing_cmd")
alt_sources=("existing_src")
record_template "testtgt" "new_cmd" "new_src"
2019-10-01 09:12:18 -04:00
{REPORT_RESULTS}
"""
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 == ""
assert "SIZE:1\n" in run.out
assert "TARGETS:testtgt\n" in run.out
assert "CMDS:new_cmd\n" in run.out
assert "SOURCES:new_src\n" in run.out