Split out processing of stale links
This commit is contained in:
parent
0438e383e5
commit
b411f9d74f
2 changed files with 42 additions and 1 deletions
37
test/test_unit_remove_stale_links.py
Normal file
37
test/test_unit_remove_stale_links.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
"""Unit tests: remove_stale_links"""
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize('linked', [True, False])
|
||||
@pytest.mark.parametrize('kind', ['file', 'symlink'])
|
||||
def test_remove_stale_links(runner, yadm, tmpdir, kind, linked):
|
||||
"""Test remove_stale_links()"""
|
||||
|
||||
source_file = tmpdir.join('source_file')
|
||||
source_file.write('source file', ensure=True)
|
||||
link = tmpdir.join('link')
|
||||
|
||||
if kind == 'file':
|
||||
link.write('link file', ensure=True)
|
||||
else:
|
||||
os.system(f'ln -s {source_file} {link}')
|
||||
|
||||
alt_linked = ''
|
||||
if linked:
|
||||
alt_linked = source_file
|
||||
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
possible_alts=({link})
|
||||
alt_linked=({alt_linked})
|
||||
function rm() {{ echo rm "$@"; }}
|
||||
remove_stale_links
|
||||
"""
|
||||
|
||||
run = runner(command=['bash'], inp=script)
|
||||
assert run.err == ''
|
||||
if kind == 'symlink' and not linked:
|
||||
assert f'rm -f {link}' in run.out
|
||||
else:
|
||||
assert run.out == ''
|
6
yadm
6
yadm
|
@ -402,6 +402,11 @@ function alt() {
|
|||
alt_future_linking
|
||||
fi
|
||||
|
||||
remove_stale_links
|
||||
|
||||
}
|
||||
|
||||
function remove_stale_links() {
|
||||
# review alternate candidates for stale links
|
||||
# if a possible alt IS linked, but it's target is not part of alt_linked,
|
||||
# remove it.
|
||||
|
@ -419,7 +424,6 @@ function alt() {
|
|||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function set_local_alt_values() {
|
||||
|
|
Loading…
Reference in a new issue