From f0f08a10e8ebfb4ea287b2b1e256676f477f144a Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Mon, 30 Oct 2017 13:48:22 +0100 Subject: [PATCH] Add unit test for file.line on an empty content while not deleting anything --- tests/unit/modules/test_file.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/modules/test_file.py b/tests/unit/modules/test_file.py index 476d814c48..a6bd979acb 100644 --- a/tests/unit/modules/test_file.py +++ b/tests/unit/modules/test_file.py @@ -872,6 +872,18 @@ class FileModuleTestCase(TestCase, LoaderModuleMockMixin): assert err_msg in str(cmd_err) @skipIf(pytest is None, 'PyTest required for this test') + @patch('os.path.realpath', MagicMock()) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_line_no_content(self): + ''' + Test for file.line for an empty content when not deleting anything. + :return: + ''' + for mode in ['insert', 'ensure', 'replace']: + with pytest.raises(CommandExecutionError) as cmd_err: + filemod.line('foo', mode=mode) + assert 'Content can only be empty if mode is "delete"' in str(cmd_err) + class FileBasicsTestCase(TestCase, LoaderModuleMockMixin): def setup_loader_modules(self):