1
0
Fork 0
mirror of synced 2024-11-17 06:45:33 -05:00

Add tests for hook executable bit

This commit is contained in:
Tim Byrne 2020-12-22 11:52:44 -06:00
parent f9337101ee
commit 74df722840
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12

View file

@ -127,6 +127,39 @@ def test_escaped(runner, yadm_cmd, paths):
'a\\ b c\\\td e\\\\f\n') in run.out
@pytest.mark.parametrize('condition', ['exec', 'no-exec', 'mingw'])
def test_executable(runner, paths, condition):
"""Verify hook must be exectuable"""
cmd = 'version'
hook = paths.hooks.join(f'pre_{cmd}')
hook.write('#!/bin/sh\necho HOOK\n')
hook.chmod(0o644)
if condition == 'exec':
hook.chmod(0o755)
mingw = 'OPERATING_SYSTEM="MINGWx"' if condition == 'mingw' else ''
script = f"""
YADM_TEST=1 source {paths.pgm}
YADM_HOOKS="{paths.hooks}"
HOOK_COMMAND="{cmd}"
{mingw}
invoke_hook "pre"
"""
run = runner(command=['bash'], inp=script)
if condition != 'mingw':
assert run.success
assert run.err == ''
else:
assert run.failure
assert 'Permission denied' in run.err
if condition == 'exec':
assert 'HOOK' in run.out
elif condition == 'no-exec':
assert 'HOOK' not in run.out
def create_hook(paths, name, code):
"""Create hook"""
hook = paths.hooks.join(name)