def test__git_run_tmp_wrapper(self): """ When an identity file is specified, make sure we don't attempt to remove a temp wrapper that wasn't created. Windows doesn't use temp wrappers, and *NIX won't unless no username was specified and the path is not executable. """ file_remove_mock = Mock() mock_true = Mock(return_value=True) mock_false = Mock(return_value=False) cmd_mock = MagicMock(return_value={ "retcode": 0, "stdout": "", "stderr": "" }) with patch.dict( git_mod.__salt__, { "file.file_exists": mock_true, "file.remove": file_remove_mock, "cmd.run_all": cmd_mock, "ssh.key_is_encrypted": mock_false, }, ): # Non-windows with patch("salt.utils.platform.is_windows", mock_false), patch.object(git_mod, "_path_is_executable_others", mock_true): # Command doesn't really matter here since we're mocking git_mod._git_run( ["git", "rev-parse", "HEAD"], cwd="/some/path", user=None, identity="/root/.ssh/id_rsa", ) file_remove_mock.assert_not_called() file_remove_mock.reset_mock() with patch("salt.utils.platform.is_windows", mock_true), patch.object( git_mod, "_find_ssh_exe", MagicMock(return_value=r"C:\Git\ssh.exe")): # Command doesn't really matter here since we're mocking git_mod._git_run( ["git", "rev-parse", "HEAD"], cwd=r"C:\some\path", user=None, identity=r"C:\ssh\id_rsa", ) file_remove_mock.assert_not_called()
def test__git_run_tmp_wrapper(self): ''' When an identity file is specified, make sure we don't attempt to remove a temp wrapper that wasn't created. Windows doesn't use temp wrappers, and *NIX won't unless no username was specified and the path is not executable. ''' file_remove_mock = Mock() mock_true = Mock(return_value=True) mock_false = Mock(return_value=False) cmd_mock = MagicMock(return_value={ 'retcode': 0, 'stdout': '', 'stderr': '', }) with patch.dict( git_mod.__salt__, { 'file.file_exists': mock_true, 'file.remove': file_remove_mock, 'cmd.run_all': cmd_mock, 'ssh.key_is_encrypted': mock_false }): # Non-windows with patch('salt.utils.platform.is_windows', mock_false), \ patch.object(git_mod, '_path_is_executable_others', mock_true): # Command doesn't really matter here since we're mocking git_mod._git_run(['git', 'rev-parse', 'HEAD'], cwd='/some/path', user=None, identity='/root/.ssh/id_rsa') file_remove_mock.assert_not_called() file_remove_mock.reset_mock() with patch('salt.utils.platform.is_windows', mock_true), \ patch.object(git_mod, '_find_ssh_exe', MagicMock(return_value=r'C:\Git\ssh.exe')): # Command doesn't really matter here since we're mocking git_mod._git_run(['git', 'rev-parse', 'HEAD'], cwd=r'C:\some\path', user=None, identity=r'C:\ssh\id_rsa') file_remove_mock.assert_not_called()