| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import os |
| 10 |
import shutil |
| 11 |
import subprocess |
| 12 |
|
| 13 |
from rsyncfns import ( |
| 14 |
FROMDIR, SRCDIR, TODIR, |
| 15 |
checkit, hands_setup, runtest, test_skipped, rsync_path_arg, rsh_cmd, |
| 16 |
) |
| 17 |
|
| 18 |
|
| 19 |
SSH = rsh_cmd() |
| 20 |
|
| 21 |
|
| 22 |
if os.environ.get('rsync_enable_ssh_tests') == 'yes': |
| 23 |
real_ssh = shutil.which('ssh') |
| 24 |
if real_ssh: |
| 25 |
SSH = real_ssh |
| 26 |
|
| 27 |
probe = subprocess.run( |
| 28 |
[SSH, '-oBatchMode yes', 'localhost', 'echo', 'yes'], |
| 29 |
capture_output=True, text=True, |
| 30 |
) |
| 31 |
if probe.stdout.strip() != 'yes': |
| 32 |
test_skipped( |
| 33 |
"Skipping SSH tests because ssh connection to localhost not authorised" |
| 34 |
) |
| 35 |
|
| 36 |
print(f"Using remote shell: {SSH}") |
| 37 |
|
| 38 |
hands_setup() |
| 39 |
|
| 40 |
|
| 41 |
from rsyncfns import RSYNC, RSYNC_PEER |
| 42 |
|
| 43 |
|
| 44 |
def _basic(): |
| 45 |
checkit(['-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}', |
| 46 |
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR) |
| 47 |
|
| 48 |
|
| 49 |
def _delete_after_rename(): |
| 50 |
shutil.move(str(TODIR / 'text'), str(TODIR / 'ThisShouldGo')) |
| 51 |
checkit(['--delete', '-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}', |
| 52 |
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR) |
| 53 |
|
| 54 |
|
| 55 |
runtest("ssh: basic test", _basic) |
| 56 |
runtest("ssh: renamed file", _delete_after_rename) |