Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blockreplace better fix #49242

Merged
merged 4 commits into from Aug 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
142 changes: 71 additions & 71 deletions tests/integration/states/test_file.py
Expand Up @@ -2647,57 +2647,57 @@ def test_issue_48336_file_managed_mode_setuid(self, user, group):
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
marker_start = '# start'
marker_end = '# end'
content = textwrap.dedent('''\
Line 1 of block
Line 2 of block
''')
without_block = textwrap.dedent('''\
Hello world!

# comment here
''')
with_non_matching_block = textwrap.dedent('''\
Hello world!

# start
No match here
# end
# comment here
''')
with_non_matching_block_and_marker_end_not_after_newline = textwrap.dedent('''\
Hello world!

# start
No match here# end
# comment here
''')
with_matching_block = textwrap.dedent('''\
Hello world!

# start
Line 1 of block
Line 2 of block
# end
# comment here
''')
with_matching_block_and_extra_newline = textwrap.dedent('''\
Hello world!

# start
Line 1 of block
Line 2 of block

# end
# comment here
''')
with_matching_block_and_marker_end_not_after_newline = textwrap.dedent('''\
Hello world!

# start
Line 1 of block
Line 2 of block# end
# comment here
''')
content = six.text_type(os.linesep.join([
'Line 1 of block',
'Line 2 of block',
'']))
without_block = six.text_type(os.linesep.join([
'Hello world!',
'',
'# comment here',
'']))
with_non_matching_block = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'No match here',
'# end',
'# comment here',
'']))
with_non_matching_block_and_marker_end_not_after_newline = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'No match here# end',
'# comment here',
'']))
with_matching_block = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'Line 1 of block',
'Line 2 of block',
'# end',
'# comment here',
'']))
with_matching_block_and_extra_newline = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'Line 1 of block',
'Line 2 of block',
'',
'# end',
'# comment here',
'']))
with_matching_block_and_marker_end_not_after_newline = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'Line 1 of block',
'Line 2 of block# end',
'# comment here',
'']))
content_explicit_posix_newlines = ('Line 1 of block\n'
'Line 2 of block\n')
content_explicit_windows_newlines = ('Line 1 of block\r\n'
Expand Down Expand Up @@ -2747,8 +2747,8 @@ def test_prepend(self, name):
Test blockreplace when prepend_if_not_found=True and block doesn't
exist in file.
'''
expected = self.marker_start + '\n' + self.content + \
self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
self.marker_end + os.linesep + self.without_block

# Pass 1: content ends in newline
self._write(name, self.without_block)
Expand Down Expand Up @@ -2801,8 +2801,8 @@ def test_prepend_append_newline(self, name):
exist in file. Test with append_newline explicitly set to True.
'''
# Pass 1: content ends in newline
expected = self.marker_start + '\n' + self.content + \
'\n' + self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
os.linesep + self.marker_end + os.linesep + self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
Expand All @@ -2827,8 +2827,8 @@ def test_prepend_append_newline(self, name):
self.assertEqual(self._read(name), expected)

# Pass 2: content does not end in newline
expected = self.marker_start + '\n' + self.content + \
self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
self.marker_end + os.linesep + self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
Expand Down Expand Up @@ -2859,8 +2859,8 @@ def test_prepend_no_append_newline(self, name):
exist in file. Test with append_newline explicitly set to False.
'''
# Pass 1: content ends in newline
expected = self.marker_start + '\n' + self.content + \
self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
self.marker_end + os.linesep + self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
Expand All @@ -2885,8 +2885,8 @@ def test_prepend_no_append_newline(self, name):
self.assertEqual(self._read(name), expected)

# Pass 2: content does not end in newline
expected = self.marker_start + '\n' + \
self.content.rstrip('\r\n') + self.marker_end + '\n' + \
expected = self.marker_start + os.linesep + \
self.content.rstrip('\r\n') + self.marker_end + os.linesep + \
self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
Expand Down Expand Up @@ -2917,8 +2917,8 @@ def test_append(self, name):
Test blockreplace when append_if_not_found=True and block doesn't
exist in file.
'''
expected = self.without_block + self.marker_start + '\n' + \
self.content + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + self.marker_end + os.linesep

# Pass 1: content ends in newline
self._write(name, self.without_block)
Expand Down Expand Up @@ -2971,8 +2971,8 @@ def test_append_append_newline(self, name):
exist in file. Test with append_newline explicitly set to True.
'''
# Pass 1: content ends in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content + '\n' + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + os.linesep + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
Expand All @@ -2997,8 +2997,8 @@ def test_append_append_newline(self, name):
self.assertEqual(self._read(name), expected)

# Pass 2: content does not end in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
Expand Down Expand Up @@ -3029,8 +3029,8 @@ def test_append_no_append_newline(self, name):
exist in file. Test with append_newline explicitly set to False.
'''
# Pass 1: content ends in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
Expand All @@ -3055,8 +3055,8 @@ def test_append_no_append_newline(self, name):
self.assertEqual(self._read(name), expected)

# Pass 2: content does not end in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content.rstrip('\r\n') + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content.rstrip('\r\n') + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
Expand Down