From 282908c57e32e9f9ef17e2a5f899b6aa8caaf452 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 5 Oct 2023 11:28:12 -0400 Subject: [PATCH] Add test coverage for winrm (#81910) --- test/units/plugins/connection/test_winrm.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/units/plugins/connection/test_winrm.py b/test/units/plugins/connection/test_winrm.py index eeff70e5786..d21d48f7a24 100644 --- a/test/units/plugins/connection/test_winrm.py +++ b/test/units/plugins/connection/test_winrm.py @@ -439,3 +439,23 @@ class TestWinRMKerbAuth(object): assert str(err.value) == \ "Kerberos auth failure for principal username with pexpect: " \ "Error with kinit\n" + + def test_exec_command_with_timeout(self, monkeypatch): + requests_exc = pytest.importorskip("requests.exceptions") + + pc = PlayContext() + new_stdin = StringIO() + conn = connection_loader.get('winrm', pc, new_stdin) + + mock_proto = MagicMock() + mock_proto.run_command.side_effect = requests_exc.Timeout("msg") + + conn._connected = True + conn._winrm_host = 'hostname' + + monkeypatch.setattr(conn, "_winrm_connect", lambda: mock_proto) + + with pytest.raises(AnsibleConnectionFailure) as e: + conn.exec_command('cmd', in_data=None, sudoable=True) + + assert str(e.value) == "winrm connection error: msg"