From e5a2f53a0db75670b3ff82ef50a857912d8669b3 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Wed, 6 Jun 2018 11:19:08 -0500 Subject: [PATCH] Update tests to reflect changes in #47580 --- salt/states/file.py | 1 + tests/unit/states/test_file.py | 45 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/salt/states/file.py b/salt/states/file.py index 7f4e81d8dd..c8ce04ccde 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -1376,6 +1376,7 @@ def symlink( os.path.dirname(name) ) ) + if __salt__['file.is_link'](name): # The link exists, verify that it matches the target if os.path.normpath(__salt__['file.readlink'](name)) != os.path.normpath(target): diff --git a/tests/unit/states/test_file.py b/tests/unit/states/test_file.py index bb5955c208..c0b4cef469 100644 --- a/tests/unit/states/test_file.py +++ b/tests/unit/states/test_file.py @@ -252,15 +252,24 @@ class TestFileState(TestCase, LoaderModuleMockMixin): with patch.object(os.path, 'isdir', mock_t): with patch.object(os.path, 'exists', mock_f): with patch.object(os.path, 'lexists', mock_t): - comt = ('File exists where the backup target SALT' - ' should go') + comt = ( + 'Symlink & backup dest exists and Force not ' + 'set. {0} -> {1} - backup: {2}'.format( + name, + target, + os.path.join(test_dir, 'SALT') + ) + ) ret.update({'comment': comt, 'result': False, 'pchanges': {'new': name}}) - self.assertDictEqual(filestate.symlink - (name, target, user=user, - group=group, backupname='SALT'), - ret) + self.assertDictEqual( + filestate.symlink( + name, target, user=user, + group=group, backupname='SALT' + ), + ret + ) with patch.dict(filestate.__salt__, {'config.manage_mode': mock_t, 'file.user_to_uid': mock_uid, @@ -270,17 +279,19 @@ class TestFileState(TestCase, LoaderModuleMockMixin): 'user.info': mock_empty, 'user.current': mock_user}): with patch.dict(filestate.__opts__, {'test': False}): - with patch.object(os.path, 'isabs', mock_t): - with patch.object(os.path, 'isabs', mock_f): - comt = ('Backupname must be an absolute path ' - 'or a file name: {0}').format('tmp/SALT') - ret.update({'comment': comt, - 'result': False, - 'pchanges': {'new': name}}) - self.assertDictEqual(filestate.symlink - (name, target, user=user, - group=group, backupname='tmp/SALT'), - ret) + with patch.object(os.path, 'isfile', mock_t): + comt = ('Backupname must be an absolute path ' + 'or a file name: {0}').format('tmp/SALT') + ret.update({'comment': comt, + 'result': False, + 'pchanges': {'new': name}}) + self.assertDictEqual( + filestate.symlink( + name, target, user=user, + group=group, backupname='tmp/SALT' + ), + ret + ) with patch.dict(filestate.__salt__, {'config.manage_mode': mock_t, 'file.user_to_uid': mock_uid,