mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
write unit test for defaults.merge
This commit is contained in:
parent
fcd2767c54
commit
6af5cd844f
@ -37,3 +37,82 @@ class DefaultsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
MagicMock(return_value={'users': {'root': [0]}})):
|
||||
self.assertEqual(defaults.get('core:users:root'),
|
||||
{'users': {'root': [0]}})
|
||||
|
||||
def test_merge_with_list_merging(self):
|
||||
'''
|
||||
Test deep merging of dicts with merge_lists enabled.
|
||||
'''
|
||||
|
||||
src_dict = {
|
||||
'string_key': 'string_val_src',
|
||||
'list_key': [
|
||||
'list_val_src',
|
||||
],
|
||||
'dict_key': {
|
||||
'dict_key_src': 'dict_val_src',
|
||||
}
|
||||
}
|
||||
|
||||
dest_dict = {
|
||||
'string_key': 'string_val_dest',
|
||||
'list_key': [
|
||||
'list_val_dest',
|
||||
],
|
||||
'dict_key': {
|
||||
'dict_key_dest': 'dict_val_dest',
|
||||
}
|
||||
}
|
||||
|
||||
merged_dict = {
|
||||
'string_key': 'string_val_src',
|
||||
'list_key': [
|
||||
'list_val_dest',
|
||||
'list_val_src'
|
||||
],
|
||||
'dict_key': {
|
||||
'dict_key_dest': 'dict_val_dest',
|
||||
'dict_key_src': 'dict_val_src'
|
||||
}
|
||||
}
|
||||
|
||||
defaults.merge(dest_dict, src_dict, merge_lists=True)
|
||||
self.assertEqual(dest_dict, merged_dict)
|
||||
|
||||
def test_merge_without_list_merging(self):
|
||||
'''
|
||||
Test deep merging of dicts with merge_lists disabled.
|
||||
'''
|
||||
|
||||
src_dict = {
|
||||
'string_key': 'string_val_src',
|
||||
'list_key': [
|
||||
'list_val_src',
|
||||
],
|
||||
'dict_key': {
|
||||
'dict_key_src': 'dict_val_src',
|
||||
}
|
||||
}
|
||||
|
||||
dest_dict = {
|
||||
'string_key': 'string_val_dest',
|
||||
'list_key': [
|
||||
'list_val_dest',
|
||||
],
|
||||
'dict_key': {
|
||||
'dict_key_dest': 'dict_val_dest',
|
||||
}
|
||||
}
|
||||
|
||||
merged_dict = {
|
||||
'string_key': 'string_val_src',
|
||||
'list_key': [
|
||||
'list_val_src'
|
||||
],
|
||||
'dict_key': {
|
||||
'dict_key_dest': 'dict_val_dest',
|
||||
'dict_key_src': 'dict_val_src'
|
||||
}
|
||||
}
|
||||
|
||||
defaults.merge(dest_dict, src_dict, merge_lists=False)
|
||||
self.assertEqual(dest_dict, merged_dict)
|
||||
|
Loading…
Reference in New Issue
Block a user