1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2024-10-27 20:34:27 +00:00
TheLocehiliosan_yadm/test/test_ext_crypt.py

49 lines
1.3 KiB
Python
Raw Normal View History

"""Test external encryption commands"""
import pytest
@pytest.mark.parametrize(
'crypt',
[False, 'installed', 'installed-but-failed'],
ids=['not-installed', 'installed', 'installed-but-failed']
)
@pytest.mark.parametrize(
'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)
bindir = tmpdir.mkdir('bin')
pgm = bindir.join('test-ext-crypt')
if crypt:
2020-12-21 21:38:31 +00:00
pgm.write('#!/bin/sh\necho ext-crypt ran\n')
pgm.chmod(0o775)
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"
"""
run = runner(command=['bash'], inp=script)
if crypt:
if crypt == 'installed-but-failed':
assert run.failure
else:
assert run.success
assert run.out.strip() == 'ext-crypt ran'
assert run.err == ''
else:
assert run.failure
assert f"command '{pgm}' cannot be located" in run.err