mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix alternatives for Windows
Not sure this is necessary... I don't think alternatives is a thing in Windows. Anyway, it uses `__salt__['file.readlink']` instead of `os.readlink` as there is no `os.readlink` in Windows. Modifies the tests to mock `__salt__['file.readlink']` instead of `os.readlink`
This commit is contained in:
parent
015cbc57d9
commit
7c4460164b
2 changed files with 9 additions and 11 deletions
|
@ -241,4 +241,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__['file.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.dict(alternatives.__salt__, {'file.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.dict(alternatives.__salt__, {'file.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