mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Add unit test for file.line replacement
This commit is contained in:
parent
9a72761dc6
commit
b4cd4bd165
@ -980,6 +980,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_replace(self):
|
||||
'''
|
||||
Test for file.line for replacement 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/natrium-chloride\n - /srv/sugar'
|
||||
for match 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='- /srv/natrium-chloride', match=match, mode='replace')
|
||||
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