From a63e2a3693b8e09799d0b26fe08e050ad911593d Mon Sep 17 00:00:00 2001 From: Marek Czernek Date: Thu, 18 Apr 2024 15:17:51 +0200 Subject: [PATCH] Add test for non-sls functions --- .../unit/modules/test_transactional_update.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/pytests/unit/modules/test_transactional_update.py b/tests/pytests/unit/modules/test_transactional_update.py index 8e5b9b996b..b6d4ede9f2 100644 --- a/tests/pytests/unit/modules/test_transactional_update.py +++ b/tests/pytests/unit/modules/test_transactional_update.py @@ -578,6 +578,34 @@ def test_call_fail_explicit_reboot(): assert not reboot_mock.called +def test_call_fail_explicit_reboot_non_sls(): + """ + Test transactional_update.call does NOT execute reboot when the word 'reboot' + appears in sls executed with function other than state.sls + """ + return_json = { + "local": { + "cmd_|-reboot_test_|-reboot_|-run": { + "name": "reboot", + "changes": {}, + "result": True, + } + } + } + utils_mock = { + "json.find_json": MagicMock(return_value=return_json), + } + salt_mock = { + "cmd.run_all": MagicMock(return_value={"retcode": 0, "stdout": ""}), + } + reboot_mock = MagicMock() + with patch.dict(tu.__utils__, utils_mock), patch.dict( + tu.__salt__, salt_mock + ), patch("salt.modules.transactional_update.reboot", reboot_mock): + tu.call("state.test") + assert not reboot_mock.called + + def test_sls(): """Test transactional_update.sls""" salt_mock = {