mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
ticket 38558: add unit test, deepcopy() only if necessary
This commit is contained in:
parent
30ae0a1958
commit
c2f98d2f04
2 changed files with 25 additions and 1 deletions
|
@ -91,10 +91,10 @@ def get(key,
|
|||
raise SaltInvocationError(
|
||||
'default must be a dictionary when merge=True'
|
||||
)
|
||||
default = copy.deepcopy(default)
|
||||
ret = salt.utils.traverse_dict_and_list(pillar_dict, key, {}, delimiter)
|
||||
if isinstance(ret, collections.Mapping) and \
|
||||
isinstance(default, collections.Mapping):
|
||||
default = copy.deepcopy(default)
|
||||
return salt.utils.dictupdate.update(default, ret)
|
||||
|
||||
ret = salt.utils.traverse_dict_and_list(pillar_dict,
|
||||
|
|
|
@ -54,6 +54,30 @@ class PillarModuleTestCase(TestCase):
|
|||
def test_ls(self):
|
||||
self.assertEqual(pillarmod.ls(), ['a', 'b'])
|
||||
|
||||
def test_pillar_get_default_merge_regression_38558(self):
|
||||
"""Test for pillar.get(key=..., default=..., merge=True)
|
||||
|
||||
Do not update the ``default`` value when using ``merge=True``.
|
||||
|
||||
See: https://github.com/saltstack/salt/issues/38558
|
||||
"""
|
||||
|
||||
pillarmod.__opts__ = {}
|
||||
pillarmod.__pillar__ = {'l1': {'l2': {'l3': 42}}}
|
||||
|
||||
res = pillarmod.get(key='l1')
|
||||
self.assertEqual({'l2': {'l3': 42}}, res)
|
||||
|
||||
default = {'l2': {'l3': 43}}
|
||||
|
||||
res = pillarmod.get(key='l1', default=default)
|
||||
self.assertEqual({'l2': {'l3': 42}}, res)
|
||||
self.assertEqual({'l2': {'l3': 43}}, default)
|
||||
|
||||
res = pillarmod.get(key='l1', default=default, merge=True)
|
||||
self.assertEqual({'l2': {'l3': 42}}, res)
|
||||
self.assertEqual({'l2': {'l3': 43}}, default)
|
||||
|
||||
|
||||
# gracinet: not sure this is really useful, but other test modules have this as well
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Reference in a new issue