Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-czernek committed Apr 18, 2024
1 parent c0e081e commit d4642ef
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/pytests/unit/modules/test_transactional_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,57 @@ def test_call_success_parameters():
)


def test_call_success_explicit_reboot():
"""Test transactional_update.call executes reboot when user specifies 'reboot' in 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("module.function", key="value")
reboot_mock.assert_called_once()


def test_call_success_explicit_reboot_test():
"""Test transactional_update.call does NOT execute reboot when user specifies 'reboot' in sls in test mode"""
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("module.function", test="True")
assert not reboot_mock.called


def test_call_fail_explicit_reboot():
"""Test transactional_update.call does NOT execute reboot when the word 'reboot' appears in sls"""
return_json = {'local': { 'cmd_|-reboot_test_|-reboot_|-run': {'name': 'service 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("module.function", test="True")
assert not reboot_mock.called


def test_sls():
"""Test transactional_update.sls"""
salt_mock = {
Expand Down

0 comments on commit d4642ef

Please sign in to comment.