From a81e0152ac0ba80614b5fa76ad6d14a8f20a8fae Mon Sep 17 00:00:00 2001 From: Tyler Levy Conde Date: Thu, 18 Apr 2024 10:43:07 -0600 Subject: [PATCH] fixed failing tests --- tests/pytests/unit/client/ssh/test_single.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/pytests/unit/client/ssh/test_single.py b/tests/pytests/unit/client/ssh/test_single.py index a69c315c215..73a7bea0aeb 100644 --- a/tests/pytests/unit/client/ssh/test_single.py +++ b/tests/pytests/unit/client/ssh/test_single.py @@ -12,6 +12,8 @@ import salt.utils.path import salt.utils.platform import salt.utils.thin import salt.utils.yaml +import salt.client.ssh.shell as shell +import importlib from salt.client import ssh from tests.support.mock import MagicMock, call, patch @@ -27,6 +29,17 @@ def opts(master_opts): ] return master_opts +@pytest.fixture() +def mock_bin_paths(): + with patch("salt.utils.path.which") as mock_which: + mock_which.side_effect = lambda x: { + "ssh-keygen": "ssh-keygen", + "ssh": "ssh", + "scp": "scp", + }.get(x, None) + importlib.reload(shell) + yield + importlib.reload(shell) @pytest.fixture def target(): @@ -45,7 +58,7 @@ def target(): } -def test_single_opts(opts, target): +def test_single_opts(opts, target, mock_bin_paths): """Sanity check for ssh.Single options""" single = ssh.Single( @@ -370,7 +383,7 @@ def test_shim_cmd_copy_fails(opts, target, caplog): mock_cmd.assert_not_called() -def test_run_ssh_pre_flight_no_connect(opts, target, tmp_path, caplog): +def test_run_ssh_pre_flight_no_connect(opts, target, tmp_path, caplog, mock_bin_paths): """ test Single.run_ssh_pre_flight when you cannot connect to the target @@ -464,7 +477,7 @@ def test_run_ssh_pre_flight_permission_denied(opts, target, tmp_path): mock_exec_cmd.assert_not_called() -def test_run_ssh_pre_flight_connect(opts, target, tmp_path, caplog): +def test_run_ssh_pre_flight_connect(opts, target, tmp_path, caplog, mock_bin_paths): """ test Single.run_ssh_pre_flight when you can connect to the target