diff options
Diffstat (limited to 'tests/test_ssh.py')
| -rw-r--r-- | tests/test_ssh.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/test_ssh.py b/tests/test_ssh.py index 5a4f27e4..ffb5cb94 100644 --- a/tests/test_ssh.py +++ b/tests/test_ssh.py | |||
| @@ -14,6 +14,8 @@ | |||
| 14 | 14 | ||
| 15 | """Unittests for the ssh.py module.""" | 15 | """Unittests for the ssh.py module.""" |
| 16 | 16 | ||
| 17 | import multiprocessing | ||
| 18 | import subprocess | ||
| 17 | import unittest | 19 | import unittest |
| 18 | from unittest import mock | 20 | from unittest import mock |
| 19 | 21 | ||
| @@ -39,14 +41,34 @@ class SshTests(unittest.TestCase): | |||
| 39 | with mock.patch('ssh._run_ssh_version', return_value='OpenSSH_1.2\n'): | 41 | with mock.patch('ssh._run_ssh_version', return_value='OpenSSH_1.2\n'): |
| 40 | self.assertEqual(ssh.version(), (1, 2)) | 42 | self.assertEqual(ssh.version(), (1, 2)) |
| 41 | 43 | ||
| 44 | def test_context_manager_empty(self): | ||
| 45 | """Verify context manager with no clients works correctly.""" | ||
| 46 | with multiprocessing.Manager() as manager: | ||
| 47 | with ssh.ProxyManager(manager): | ||
| 48 | pass | ||
| 49 | |||
| 50 | def test_context_manager_child_cleanup(self): | ||
| 51 | """Verify orphaned clients & masters get cleaned up.""" | ||
| 52 | with multiprocessing.Manager() as manager: | ||
| 53 | with ssh.ProxyManager(manager) as ssh_proxy: | ||
| 54 | client = subprocess.Popen(['sleep', '964853320']) | ||
| 55 | ssh_proxy.add_client(client) | ||
| 56 | master = subprocess.Popen(['sleep', '964853321']) | ||
| 57 | ssh_proxy.add_master(master) | ||
| 58 | # If the process still exists, these will throw timeout errors. | ||
| 59 | client.wait(0) | ||
| 60 | master.wait(0) | ||
| 61 | |||
| 42 | def test_ssh_sock(self): | 62 | def test_ssh_sock(self): |
| 43 | """Check sock() function.""" | 63 | """Check sock() function.""" |
| 64 | manager = multiprocessing.Manager() | ||
| 65 | proxy = ssh.ProxyManager(manager) | ||
| 44 | with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'): | 66 | with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'): |
| 45 | # old ssh version uses port | 67 | # old ssh version uses port |
| 46 | with mock.patch('ssh.version', return_value=(6, 6)): | 68 | with mock.patch('ssh.version', return_value=(6, 6)): |
| 47 | self.assertTrue(ssh.sock().endswith('%p')) | 69 | self.assertTrue(proxy.sock().endswith('%p')) |
| 48 | ssh._ssh_sock_path = None | 70 | |
| 71 | proxy._sock_path = None | ||
| 49 | # new ssh version uses hash | 72 | # new ssh version uses hash |
| 50 | with mock.patch('ssh.version', return_value=(6, 7)): | 73 | with mock.patch('ssh.version', return_value=(6, 7)): |
| 51 | self.assertTrue(ssh.sock().endswith('%C')) | 74 | self.assertTrue(proxy.sock().endswith('%C')) |
| 52 | ssh._ssh_sock_path = None | ||
