mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Add unit test for file.line delete by direct match or regular expression
This commit is contained in:
parent
60185f578e
commit
9a72761dc6
@ -959,6 +959,27 @@ class FilemodLineTests(TestCase, LoaderModuleMockMixin):
|
||||
assert 1 == len(atomic_opener().write.call_args_list)
|
||||
assert file_modified == atomic_opener().write.call_args_list[0][0][0]
|
||||
|
||||
@patch('os.path.realpath', MagicMock())
|
||||
@patch('os.path.isfile', MagicMock(return_value=True))
|
||||
@patch('os.stat', MagicMock())
|
||||
def test_line_delete(self):
|
||||
'''
|
||||
Test for file.line for deletion of specific line
|
||||
|
||||
See issue #38670
|
||||
:return:
|
||||
'''
|
||||
file_content = 'file_roots:\n base:\n - /srv/salt\n - /srv/pepper\n - /srv/sugar'
|
||||
file_modified = 'file_roots:\n base:\n - /srv/salt\n - /srv/sugar'
|
||||
for content in ['/srv/pepper', '/srv/pepp*', '/srv/p.*', '/sr.*pe.*']:
|
||||
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):
|
||||
filemod.line('foo', content=content, mode='delete')
|
||||
assert 1 == len(atomic_opener().write.call_args_list)
|
||||
assert file_modified == atomic_opener().write.call_args_list[0][0][0]
|
||||
|
||||
|
||||
class FileBasicsTestCase(TestCase, LoaderModuleMockMixin):
|
||||
def setup_loader_modules(self):
|
||||
|
Loading…
Reference in New Issue
Block a user