mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add _available_services function for testing
This commit is contained in:
parent
6080633613
commit
781880f0fc
2 changed files with 30 additions and 17 deletions
|
@ -280,20 +280,14 @@ def launchctl(sub_cmd, *args, **kwargs):
|
|||
return ret['stdout'] if return_stdout else True
|
||||
|
||||
|
||||
@decorators.memoize
|
||||
def available_services():
|
||||
def _available_services():
|
||||
'''
|
||||
Return a dictionary of all available services on the system
|
||||
|
||||
Returns:
|
||||
dict: All available services
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
import salt.utils.mac_service
|
||||
salt.utils.mac_service.available_services()
|
||||
This is a helper function needed for testing. We are using the memoziation
|
||||
decorator on the `available_services` function, which causes the function
|
||||
to run once and then return the results of the first run on subsequent
|
||||
calls. This causes problems when trying to test the functionality of the
|
||||
`available_services` function. So this function is needed until we can
|
||||
figure out how to properly mock the memoization decorator.
|
||||
'''
|
||||
launchd_paths = [
|
||||
'/Library/LaunchAgents',
|
||||
|
@ -348,3 +342,22 @@ def available_services():
|
|||
'plist': plist}
|
||||
|
||||
return _available_services
|
||||
|
||||
|
||||
|
||||
@decorators.memoize
|
||||
def available_services():
|
||||
'''
|
||||
Return a dictionary of all available services on the system
|
||||
|
||||
Returns:
|
||||
dict: All available services
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
import salt.utils.mac_service
|
||||
salt.utils.mac_service.available_services()
|
||||
'''
|
||||
return _available_services()
|
||||
|
|
|
@ -241,7 +241,7 @@ class MacUtilsTestCase(TestCase):
|
|||
]
|
||||
|
||||
mock_exists.return_value = True
|
||||
ret = mac_utils.available_services()
|
||||
ret = mac_utils._available_services()
|
||||
|
||||
# Make sure it's a dict with 8 items
|
||||
self.assertTrue(isinstance(ret, dict))
|
||||
|
@ -289,7 +289,7 @@ class MacUtilsTestCase(TestCase):
|
|||
]
|
||||
|
||||
mock_exists.side_effect = [True, True, True, True, False, False, True, True]
|
||||
ret = mac_utils.available_services()
|
||||
ret = mac_utils._available_services()
|
||||
|
||||
# Make sure it's a dict with 6 items
|
||||
self.assertTrue(isinstance(ret, dict))
|
||||
|
@ -347,7 +347,7 @@ class MacUtilsTestCase(TestCase):
|
|||
MagicMock(Label='com.apple.slld2'),
|
||||
]
|
||||
|
||||
ret = mac_utils.available_services()
|
||||
ret = mac_utils._available_services()
|
||||
|
||||
cmd = '/usr/bin/plutil -convert xml1 -o - -- "{0}"'
|
||||
calls = [
|
||||
|
@ -425,7 +425,7 @@ class MacUtilsTestCase(TestCase):
|
|||
mock_run.return_value = '<some xml>'
|
||||
mock_read_plist_from_string.return_value = 'malformedness'
|
||||
|
||||
ret = mac_utils.available_services()
|
||||
ret = mac_utils._available_services()
|
||||
|
||||
cmd = '/usr/bin/plutil -convert xml1 -o - -- "{0}"'
|
||||
calls = [
|
||||
|
|
Loading…
Add table
Reference in a new issue