2018-07-11 08:50:42 -04:00
|
|
|
"""Unit tests: yadm.[git,gpg]-program"""
|
|
|
|
|
|
|
|
import os
|
2023-07-10 10:14:33 -04:00
|
|
|
|
2018-07-11 08:50:42 -04:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 15:43:17 -04:00
|
|
|
"executable, success, value, match",
|
|
|
|
[
|
|
|
|
(None, True, "program", None),
|
|
|
|
("cat", True, "cat", None),
|
|
|
|
("badprogram", False, None, "badprogram"),
|
|
|
|
],
|
|
|
|
ids=[
|
|
|
|
"executable missing",
|
|
|
|
"valid alternative",
|
|
|
|
"invalid alternative",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.parametrize("program", ["git", "gpg"])
|
|
|
|
def test_x_program(runner, yadm_cmd, paths, program, executable, success, value, match):
|
2018-07-11 08:50:42 -04:00
|
|
|
"""Set yadm.X-program, and test result of require_X"""
|
|
|
|
|
|
|
|
# set configuration
|
|
|
|
if executable:
|
2023-07-10 15:43:17 -04:00
|
|
|
os.system(" ".join(yadm_cmd("config", f"yadm.{program}-program", executable)))
|
2018-07-11 08:50:42 -04:00
|
|
|
|
|
|
|
# test require_[git,gpg]
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {paths.pgm}
|
2021-01-05 15:56:50 -05:00
|
|
|
YADM_OVERRIDE_CONFIG="{paths.config}"
|
|
|
|
configure_paths
|
2018-07-11 08:50:42 -04:00
|
|
|
require_{program}
|
|
|
|
echo ${program.upper()}_PROGRAM
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.success == success
|
|
|
|
|
|
|
|
# [GIT,GPG]_PROGRAM set correctly
|
2023-07-10 15:43:17 -04:00
|
|
|
if value == "program":
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.out.rstrip() == program
|
|
|
|
elif value:
|
|
|
|
assert run.out.rstrip() == value
|
|
|
|
|
|
|
|
# error reported about bad config
|
|
|
|
if match:
|
2021-01-05 15:57:32 -05:00
|
|
|
assert match in run.err
|
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|