mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #43320 from twangboy/win_fix_alternatives
Fix `unit.modules.test_alternatives` for Windows
This commit is contained in:
commit
a9592dd3e2
2 changed files with 10 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Add table
Reference in a new issue