mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #35688 from cachedout/issue_33525
Splat serializer default configs into the serializer kwargs
This commit is contained in:
commit
de06116075
2 changed files with 35 additions and 2 deletions
|
@ -4531,6 +4531,11 @@ def serialize(name,
|
|||
'''
|
||||
name = os.path.expanduser(name)
|
||||
|
||||
default_serializer_opts = {'yaml.serialize': {'default_flow_style': False},
|
||||
'json.serialize': {'indent': 2,
|
||||
'separators': (',', ': '),
|
||||
'sort_keys': True}
|
||||
}
|
||||
ret = {'changes': {},
|
||||
'comment': '',
|
||||
'name': name,
|
||||
|
@ -4608,8 +4613,7 @@ def serialize(name,
|
|||
ret['comment'] = 'The file {0} is in the correct state'.format(name)
|
||||
return ret
|
||||
dataset = merged_data
|
||||
|
||||
contents = __serializers__[serializer_name](dataset)
|
||||
contents = __serializers__[serializer_name](dataset, **default_serializer_opts.get(serializer_name, {}))
|
||||
|
||||
contents += '\n'
|
||||
|
||||
|
|
|
@ -1110,6 +1110,35 @@ class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
|||
finally:
|
||||
os.remove(path_test)
|
||||
|
||||
def test_serialize(self):
|
||||
'''
|
||||
Test to ensure that file.serialize returns a data structure that's
|
||||
both serialized and formatted properly
|
||||
'''
|
||||
path_test = os.path.join(integration.TMP, 'test_serialize')
|
||||
ret = self.run_state('file.serialize',
|
||||
name=path_test,
|
||||
dataset={'name': 'naive',
|
||||
'description': 'A basic test',
|
||||
'a_list': ['first_element', 'second_element'],
|
||||
'finally': 'the last item'},
|
||||
formatter='json')
|
||||
|
||||
with salt.utils.fopen(path_test, 'r') as fp_:
|
||||
serialized_file = fp_.read()
|
||||
|
||||
expected_file = '''{
|
||||
"a_list": [
|
||||
"first_element",
|
||||
"second_element"
|
||||
],
|
||||
"description": "A basic test",
|
||||
"finally": "the last item",
|
||||
"name": "naive"
|
||||
}
|
||||
'''
|
||||
self.assertEqual(serialized_file, expected_file)
|
||||
|
||||
def test_replace_issue_18841_omit_backup(self):
|
||||
'''
|
||||
Test the (mis-)behaviour of file.replace as described in #18841:
|
||||
|
|
Loading…
Add table
Reference in a new issue