Merge pull request #43320 from twangboy/win_fix_alternatives

Fix `unit.modules.test_alternatives` for Windows
This commit is contained in:
Mike Place 2017-09-11 11:27:59 -06:00 committed by GitHub
commit a9592dd3e2
2 changed files with 10 additions and 11 deletions

View file

@ -12,6 +12,7 @@ import logging
# Import Salt libs
import salt.utils
import salt.utils.path
# Import 3rd-party libs
import salt.ext.six as six
@ -241,4 +242,4 @@ def _read_link(name):
Throws an OSError if the link does not exist
'''
alt_link_path = '/etc/alternatives/{0}'.format(name)
return os.readlink(alt_link_path)
return salt.utils.path.readlink(alt_link_path)

View file

@ -66,30 +66,28 @@ class AlternativesTestCase(TestCase, LoaderModuleMockMixin):
)
def test_show_current(self):
with patch('os.readlink') as os_readlink_mock:
os_readlink_mock.return_value = '/etc/alternatives/salt'
mock = MagicMock(return_value='/etc/alternatives/salt')
with patch('salt.utils.path.readlink', mock):
ret = alternatives.show_current('better-world')
self.assertEqual('/etc/alternatives/salt', ret)
os_readlink_mock.assert_called_once_with(
'/etc/alternatives/better-world'
)
mock.assert_called_once_with('/etc/alternatives/better-world')
with TestsLoggingHandler() as handler:
os_readlink_mock.side_effect = OSError('Hell was not found!!!')
mock.side_effect = OSError('Hell was not found!!!')
self.assertFalse(alternatives.show_current('hell'))
os_readlink_mock.assert_called_with('/etc/alternatives/hell')
mock.assert_called_with('/etc/alternatives/hell')
self.assertIn('ERROR:alternative: hell does not exist',
handler.messages)
def test_check_installed(self):
with patch('os.readlink') as os_readlink_mock:
os_readlink_mock.return_value = '/etc/alternatives/salt'
mock = MagicMock(return_value='/etc/alternatives/salt')
with patch('salt.utils.path.readlink', mock):
self.assertTrue(
alternatives.check_installed(
'better-world', '/etc/alternatives/salt'
)
)
os_readlink_mock.return_value = False
mock.return_value = False
self.assertFalse(
alternatives.check_installed(
'help', '/etc/alternatives/salt'