-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(scp): Add unit tests for getting remote files
This tests the current behaviour of the xfunc_scp_compgen_remote_files function, including escaping, by introducing a fixture to mock ssh invocation on the local host.
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
test/fixtures/_comp_compgen_xfunc_scp_remote_files/bin/ssh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
for arg in "$@"; do | ||
case "$arg" in | ||
-o) | ||
shift 2;; | ||
local) | ||
shift 1;; | ||
esac | ||
done | ||
$@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
|
||
from conftest import assert_bash_exec, bash_env_saved | ||
|
||
|
||
@pytest.mark.bashcomp(cmd="ssh", ignore_env=r"^\+COMPREPLY=") | ||
class TestUnitXfuncScpRemoteFiles: | ||
@pytest.fixture(scope="class") | ||
def ssh_path(self, request, bash): | ||
with bash_env_saved(bash) as bash_env: | ||
bash_env.write_variable( | ||
"PATH", | ||
"$PWD/_comp_compgen_xfunc_scp_remote_files/bin:$PATH", | ||
quote=False, | ||
) | ||
yield | ||
|
||
def test_1(self, bash, ssh_path): | ||
completions = ( | ||
assert_bash_exec( | ||
bash, | ||
r'cur=local:shared/default/ _comp_compgen -ax scp remote_files; printf "%s\n" "${COMPREPLY[@]}"; unset cur', | ||
want_output=True, | ||
) | ||
.strip() | ||
.splitlines() | ||
) | ||
assert completions == [ | ||
"shared/default/bar ", | ||
r"shared/default/bar\\\ bar.d/", | ||
"shared/default/foo ", | ||
"shared/default/foo.d/", | ||
] |