mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
/sr.* pattern should raise exception
This commit is contained in:
parent
935a9b9d56
commit
3af551ebe1
1 changed files with 26 additions and 0 deletions
|
@ -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):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue