Add new unit test to check state.apply within module.run

This commit is contained in:
Pablo Suárez Hernández 2018-03-07 15:43:52 +00:00
parent 9f19ad5264
commit 885751634e
No known key found for this signature in database
GPG key ID: A9683F02B512C911

View file

@ -25,6 +25,57 @@ log = logging.getLogger(__name__)
CMD = 'foo.bar'
STATE_APPLY_RET = {
'module_|-test2_|-state.apply_|-run': {
'comment': 'Module function state.apply executed',
'name': 'state.apply',
'start_time': '16:11:48.818932',
'result': False,
'duration': 179.439,
'__run_num__': 0,
'changes': {
'ret': {
'module_|-test3_|-state.apply_|-run': {
'comment': 'Module function state.apply executed',
'name': 'state.apply',
'start_time': '16:11:48.904796',
'result': True,
'duration': 89.522,
'__run_num__': 0,
'changes': {
'ret': {
'module_|-test4_|-cmd.run_|-run': {
'comment': 'Module function cmd.run executed',
'name': 'cmd.run',
'start_time': '16:11:48.988574',
'result': True,
'duration': 4.543,
'__run_num__': 0,
'changes': {
'ret': 'Wed Mar 7 16:11:48 CET 2018'
},
'__id__': 'test4'
}
}
},
'__id__': 'test3'
},
'module_|-test3_fail_|-test3_fail_|-run': {
'comment': 'Module function test3_fail is not available',
'name': 'test3_fail',
'start_time': '16:11:48.994607',
'result': False,
'duration': 0.466,
'__run_num__': 1,
'changes': {},
'__id__': 'test3_fail'
}
}
},
'__id__': 'test2'
}
}
def _mocked_func_named(name, names=('Fred', 'Swen',)):
'''
@ -143,6 +194,17 @@ class ModuleStateTest(TestCase, LoaderModuleMockMixin):
if ret['comment'] != '{0}: Success'.format(CMD) or not ret['result']:
self.fail('module.run failed: {0}'.format(ret))
def test_run_state_apply_result_false(self):
'''
Tests the 'result' of module.run that calls state.apply execution module
:return:
'''
with patch.dict(module.__salt__, {"state.apply": MagicMock(return_value=STATE_APPLY_RET)}):
with patch.dict(module.__opts__, {'use_deprecated': ['module.run']}):
ret = module.run(**{"name": "state.apply", 'mods': 'test2'})
if ret['result']:
self.fail('module.run did not report false result: {0}'.format(ret))
def test_run_unexpected_keywords(self):
with patch.dict(module.__salt__, {CMD: _mocked_func_args}):
with patch.dict(module.__opts__, {'use_superseded': ['module.run']}):