/sr.* pattern should raise exception

This commit is contained in:
Jerzy Drozdz 2018-03-01 23:45:45 +01:00 committed by rallytime
parent 935a9b9d56
commit 3af551ebe1
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19

View file

@ -1157,6 +1157,32 @@ class FilemodLineTests(TestCase, LoaderModuleMockMixin):
write_content = handles[0].write.call_args_list[0][0][0]
assert write_content == file_modified, write_content
@patch('os.path.realpath', MagicMock())
@patch('os.path.isfile', MagicMock(return_value=True))
@patch('os.stat', MagicMock())
def test_line_assert_exception_pattern(self):
'''
Test for file.line for exception on insert with too general pattern.
:return:
'''
file_content = os.linesep.join([
'file_roots:',
' base:',
' - /srv/salt',
' - /srv/sugar'
])
cfg_content = '- /srv/custom'
for before_line in ['/sr.*']:
files_fopen = mock_open(read_data=file_content)
with patch('salt.utils.files.fopen', files_fopen):
atomic_opener = mock_open()
with patch('salt.utils.atomicfile.atomic_open', atomic_opener):
with self.assertRaises(CommandExecutionError) as cm:
filemod.line('foo', content=cfg_content, before=before_line, mode='insert')
self.assertEqual(cm.exception.strerror,
'Found more than expected occurrences in "before" expression')
@with_tempfile()
def test_line_insert_before_after(self, name):
'''