Move find_executable to utils (#1799)

We don't want to import the whole patroni.ctl into the patroni
This commit is contained in:
Alexander Kukushkin
2020-12-16 18:58:54 +01:00
committed by GitHub
parent 3a87d0e99b
commit 9b263dc6c9
5 changed files with 42 additions and 40 deletions
+10 -1
View File
@@ -2,7 +2,7 @@ import unittest
from mock import Mock, patch
from patroni.exceptions import PatroniException
from patroni.utils import Retry, RetryFailedError, enable_keepalive, polling_loop, validate_directory
from patroni.utils import Retry, RetryFailedError, enable_keepalive, find_executable, polling_loop, validate_directory
class TestUtils(unittest.TestCase):
@@ -41,6 +41,15 @@ class TestUtils(unittest.TestCase):
with patch('sys.platform', platform):
self.assertIsNone(enable_keepalive(Mock(), 10, 5))
@patch('sys.platform', 'win32')
def test_find_executable(self):
with patch('os.path.isfile', Mock(return_value=True)):
self.assertEqual(find_executable('vim'), 'vim.exe')
with patch('os.path.isfile', Mock(return_value=False)):
self.assertIsNone(find_executable('vim'))
with patch('os.path.isfile', Mock(side_effect=[False, True])):
self.assertEqual(find_executable('vim', '/'), '/vim.exe')
@patch('time.sleep', Mock())
class TestRetrySleeper(unittest.TestCase):