summaryrefslogtreecommitdiffstats
path: root/roles/lib_openshift/src/test/unit/test_oc_scale.py
diff options
context:
space:
mode:
authorJason DeTiberus <jdetiber@redhat.com>2017-02-18 20:01:53 -0500
committerJason DeTiberus <jdetiber@redhat.com>2017-02-21 23:39:32 -0500
commita3603a5187839e25e9d8a51de70fea0b68439839 (patch)
treec6f9dd5beb19a1d6a7df42ee77a3688e9237e3bc /roles/lib_openshift/src/test/unit/test_oc_scale.py
parent4b8328fe94015b25209d9b3e6c94b2a3cd0cff40 (diff)
downloadopenshift-a3603a5187839e25e9d8a51de70fea0b68439839.tar.gz
openshift-a3603a5187839e25e9d8a51de70fea0b68439839.tar.bz2
openshift-a3603a5187839e25e9d8a51de70fea0b68439839.tar.xz
openshift-a3603a5187839e25e9d8a51de70fea0b68439839.zip
lib_openshift oc file lookup improvements
- Move binary file search to separate method called from constructor - Use six.PY3 instaed of sys.version_info - Combine additional paths with the paths from the environment - For py3 pass the combined paths to shutil.which - For py2 explictly search for existance of file from combined paths instead of using distutils.spawn.find_executable and falling back - Use 'oc adm' instead of 'oadm' - Fix generate_validation test issue - fix tests for oc binary location - add tests for file lookup
Diffstat (limited to 'roles/lib_openshift/src/test/unit/test_oc_scale.py')
-rwxr-xr-xroles/lib_openshift/src/test/unit/test_oc_scale.py111
1 files changed, 110 insertions, 1 deletions
diff --git a/roles/lib_openshift/src/test/unit/test_oc_scale.py b/roles/lib_openshift/src/test/unit/test_oc_scale.py
index f15eb164d..b2dec2fbe 100755
--- a/roles/lib_openshift/src/test/unit/test_oc_scale.py
+++ b/roles/lib_openshift/src/test/unit/test_oc_scale.py
@@ -11,6 +11,7 @@
# OK
import os
+import six
import sys
import unittest
import mock
@@ -23,7 +24,7 @@ import mock
# place class in our python path
module_path = os.path.join('/'.join(os.path.realpath(__file__).split('/')[:-4]), 'library') # noqa: E501
sys.path.insert(0, module_path)
-from oc_scale import OCScale # noqa: E402
+from oc_scale import OCScale, locate_oc_binary # noqa: E402
class OCScaleTest(unittest.TestCase):
@@ -158,6 +159,114 @@ class OCScaleTest(unittest.TestCase):
self.assertTrue(results['failed'])
self.assertEqual(results['msg']['returncode'], 1)
+ @unittest.skipIf(six.PY3, 'py2 test only')
+ @mock.patch('os.path.exists')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_fallback(self, mock_env_get, mock_path_exists):
+ ''' Testing binary lookup fallback '''
+
+ mock_env_get.side_effect = lambda _v, _d: ''
+
+ mock_path_exists.side_effect = lambda _: False
+
+ self.assertEqual(locate_oc_binary(), 'oc')
+
+ @unittest.skipIf(six.PY3, 'py2 test only')
+ @mock.patch('os.path.exists')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_in_path(self, mock_env_get, mock_path_exists):
+ ''' Testing binary lookup in path '''
+
+ oc_bin = '/usr/bin/oc'
+
+ mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin'
+
+ mock_path_exists.side_effect = lambda f: f == oc_bin
+
+ self.assertEqual(locate_oc_binary(), oc_bin)
+
+ @unittest.skipIf(six.PY3, 'py2 test only')
+ @mock.patch('os.path.exists')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_in_usr_local(self, mock_env_get, mock_path_exists):
+ ''' Testing binary lookup in /usr/local/bin '''
+
+ oc_bin = '/usr/local/bin/oc'
+
+ mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin'
+
+ mock_path_exists.side_effect = lambda f: f == oc_bin
+
+ self.assertEqual(locate_oc_binary(), oc_bin)
+
+ @unittest.skipIf(six.PY3, 'py2 test only')
+ @mock.patch('os.path.exists')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_in_home(self, mock_env_get, mock_path_exists):
+ ''' Testing binary lookup in ~/bin '''
+
+ oc_bin = os.path.expanduser('~/bin/oc')
+
+ mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin'
+
+ mock_path_exists.side_effect = lambda f: f == oc_bin
+
+ self.assertEqual(locate_oc_binary(), oc_bin)
+
+ @unittest.skipIf(six.PY2, 'py3 test only')
+ @mock.patch('shutil.which')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_fallback_py3(self, mock_env_get, mock_shutil_which):
+ ''' Testing binary lookup fallback '''
+
+ mock_env_get.side_effect = lambda _v, _d: ''
+
+ mock_shutil_which.side_effect = lambda _f, path=None: None
+
+ self.assertEqual(locate_oc_binary(), 'oc')
+
+ @unittest.skipIf(six.PY2, 'py3 test only')
+ @mock.patch('shutil.which')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_in_path_py3(self, mock_env_get, mock_shutil_which):
+ ''' Testing binary lookup in path '''
+
+ oc_bin = '/usr/bin/oc'
+
+ mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin'
+
+ mock_shutil_which.side_effect = lambda _f, path=None: oc_bin
+
+ self.assertEqual(locate_oc_binary(), oc_bin)
+
+ @unittest.skipIf(six.PY2, 'py3 test only')
+ @mock.patch('shutil.which')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_in_usr_local_py3(self, mock_env_get, mock_shutil_which):
+ ''' Testing binary lookup in /usr/local/bin '''
+
+ oc_bin = '/usr/local/bin/oc'
+
+ mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin'
+
+ mock_shutil_which.side_effect = lambda _f, path=None: oc_bin
+
+ self.assertEqual(locate_oc_binary(), oc_bin)
+
+ @unittest.skipIf(six.PY2, 'py3 test only')
+ @mock.patch('shutil.which')
+ @mock.patch('os.environ.get')
+ def test_binary_lookup_in_home_py3(self, mock_env_get, mock_shutil_which):
+ ''' Testing binary lookup in ~/bin '''
+
+ oc_bin = os.path.expanduser('~/bin/oc')
+
+ mock_env_get.side_effect = lambda _v, _d: '/bin:/usr/bin'
+
+ mock_shutil_which.side_effect = lambda _f, path=None: oc_bin
+
+ self.assertEqual(locate_oc_binary(), oc_bin)
+
def tearDown(self):
'''TearDown method'''
pass