mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #37680 from rallytime/bp-32965
Back-port #32965 to 2016.3
This commit is contained in:
commit
a743d8b5e6
2 changed files with 35 additions and 1 deletions
|
@ -333,7 +333,7 @@ def _check_key_type(key_str, key_type=None):
|
|||
value = __salt__['pillar.get'](key_str, None)
|
||||
if value is None:
|
||||
return None
|
||||
elif type(value) is not key_type:
|
||||
elif type(value) is not key_type and key_type is not None:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
|
|
@ -11,6 +11,7 @@ from salttesting import TestCase, skipIf
|
|||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.mock import (
|
||||
patch,
|
||||
MagicMock,
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON
|
||||
)
|
||||
|
@ -296,6 +297,39 @@ class TestTestCase(TestCase):
|
|||
'comment': 'Watch statement fired.'})
|
||||
self.assertDictEqual(test.mod_watch('salt'), ret)
|
||||
|
||||
def test_check_pillar_present(self):
|
||||
'''
|
||||
Test to ensure the check_pillar function
|
||||
works properly with the 'present' keyword in
|
||||
the absence of a 'type' keyword.
|
||||
'''
|
||||
ret = {
|
||||
'name': 'salt',
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': ''
|
||||
}
|
||||
pillar_return = 'I am a pillar.'
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertEqual(test.check_pillar('salt', present='my_pillar'), ret)
|
||||
|
||||
def test_check_pillar_dictionary(self):
|
||||
'''
|
||||
Test to ensure the check_pillar function
|
||||
works properly with the 'key_type' checks,
|
||||
using the dictionary key_type.
|
||||
'''
|
||||
ret = {
|
||||
'name': 'salt',
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': ''
|
||||
}
|
||||
pillar_return = {'this': 'dictionary'}
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue