3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # pylint: disable=missing-docstring
16 from functest.cli.commands import cli_env
17 from functest.utils.constants import CONST
20 class RegexMatch(object):
21 def __init__(self, msg):
24 def __eq__(self, other):
25 match = re.search(self.msg, other)
31 class CliEnvTesting(unittest.TestCase):
34 self.cli_environ = cli_env.CliEnv()
36 def _test_show_missing_env_var(self, var, *args):
37 if var == 'INSTALLER_TYPE':
38 CONST.__setattr__('INSTALLER_TYPE', None)
39 reg_string = "| INSTALLER: Unknown, \S+\s*|"
40 elif var == 'INSTALLER_IP':
41 CONST.__setattr__('INSTALLER_IP', None)
42 reg_string = "| INSTALLER: \S+, Unknown\s*|"
43 elif var == 'SCENARIO':
44 CONST.__setattr__('DEPLOY_SCENARIO', None)
45 reg_string = "| SCENARIO: Unknown\s*|"
47 CONST.__setattr__('NODE_NAME', None)
48 reg_string = "| POD: Unknown\s*|"
49 elif var == 'BUILD_TAG':
50 CONST.__setattr__('BUILD_TAG', None)
51 reg_string = "| BUILD TAG: None|"
53 CONST.__setattr__('CI_DEBUG', None)
54 reg_string = "| DEBUG FLAG: false\s*|"
56 with mock.patch('functest.cli.commands.cli_env.click.echo') \
58 self.cli_environ.show()
59 mock_click_echo.assert_called_with(RegexMatch(reg_string))
61 def test_show_missing_ci_installer_type(self, *args):
62 self._test_show_missing_env_var('INSTALLER_TYPE', *args)
64 def test_show_missing_ci_installer_ip(self, *args):
65 self._test_show_missing_env_var('INSTALLER_IP', *args)
67 def test_show_missing_ci_scenario(self, *args):
68 self._test_show_missing_env_var('SCENARIO', *args)
70 def test_show_missing_ci_node(self, *args):
71 self._test_show_missing_env_var('NODE', *args)
73 def test_show_missing_ci_build_tag(self, *args):
74 self._test_show_missing_env_var('BUILD_TAG', *args)
76 def test_show_missing_ci_debug(self, *args):
77 self._test_show_missing_env_var('DEBUG', *args)
80 if __name__ == "__main__":
81 logging.disable(logging.CRITICAL)
82 unittest.main(verbosity=2)