1
0
Fork 0
mirror of synced 2024-12-22 06:31:07 -05:00
yadm/test/test_ext_crypt.py

51 lines
1.2 KiB
Python
Raw Normal View History

"""Test external encryption commands"""
import pytest
@pytest.mark.parametrize(
2023-07-10 15:43:17 -04:00
"crypt",
[False, "installed", "installed-but-failed"],
ids=["not-installed", "installed", "installed-but-failed"],
)
@pytest.mark.parametrize(
2023-07-10 15:43:17 -04:00
"cmd,var",
[
["git_crypt", "GIT_CRYPT_PROGRAM"],
["transcrypt", "TRANSCRYPT_PROGRAM"],
],
ids=["git-crypt", "transcrypt"],
)
def test_ext_encryption(runner, yadm, paths, tmpdir, crypt, cmd, var):
"""External encryption tests"""
paths.repo.ensure(dir=True)
2023-07-10 15:43:17 -04:00
bindir = tmpdir.mkdir("bin")
pgm = bindir.join("test-ext-crypt")
if crypt:
2023-07-10 15:43:17 -04:00
pgm.write("#!/bin/sh\necho ext-crypt ran\n")
pgm.chmod(0o775)
2023-07-10 15:43:17 -04:00
if crypt == "installed-but-failed":
pgm.write("false\n", mode="a")
script = f"""
YADM_TEST=1 source {yadm}
YADM_REPO={paths.repo}
{var}="{pgm}"
{cmd} "param1"
"""
2023-07-10 15:43:17 -04:00
run = runner(command=["bash"], inp=script)
if crypt:
2023-07-10 15:43:17 -04:00
if crypt == "installed-but-failed":
assert run.failure
else:
assert run.success
2023-07-10 15:43:17 -04:00
assert run.out.strip() == "ext-crypt ran"
assert run.err == ""
else:
assert run.failure
assert f"command '{pgm}' cannot be located" in run.err