Skip to content

Commit

Permalink
Add test case to assert that salt.client.ssh.SSH.fsclient.destroy()
Browse files Browse the repository at this point in the history
… is called.

Signed-off-by: Pedro Algarvio <[email protected]>
  • Loading branch information
s0undt3ch committed Apr 28, 2023
1 parent ffb015f commit eef70b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/64184.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make sure the `salt-ssh` CLI calls it's `fsclient.destroy()` method when done.
5 changes: 4 additions & 1 deletion salt/cli/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ def run(self):
self.parse_args()

ssh = salt.client.ssh.SSH(self.config)
ssh.run()
try:
ssh.run()
finally:
ssh.fsclient.destroy()
16 changes: 16 additions & 0 deletions tests/pytests/unit/cli/test_ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from salt.cli.ssh import SaltSSH
from tests.support.mock import MagicMock, call, patch


def test_fsclient_destroy_called(minion_opts):
"""
Test that `salt.client.ssh.SSH.fsclient.destroy()` is called.
"""
ssh_mock = MagicMock()
with patch(
"salt.utils.parsers.SaltSSHOptionParser.parse_args", return_value=MagicMock()
), patch("salt.client.ssh.SSH", return_value=ssh_mock):
parser = SaltSSH()
parser.config = minion_opts
parser.run()
assert ssh_mock.fsclient.mock_calls == [call.destroy()]

0 comments on commit eef70b2

Please sign in to comment.