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
17 from functest.cli.commands import cli_env
20 class RegexMatch(object): # pylint: disable=too-few-public-methods
21 def __init__(self, msg):
24 def __eq__(self, other):
25 match = re.search(self.msg, other)
26 return match is not None
29 class CliEnvTesting(unittest.TestCase):
32 self.cli_environ = cli_env.CliEnv()
34 def _test_show_missing_env_var(self, var, *args):
35 # pylint: disable=unused-argument
36 if var == 'INSTALLER_TYPE':
37 os.environ['INSTALLER_TYPE'] = ''
38 reg_string = r"| INSTALLER: Unknown, \S+\s*|"
39 elif var == 'SCENARIO':
40 os.environ['DEPLOY_SCENARIO'] = ''
41 reg_string = r"| SCENARIO: Unknown\s*|"
43 os.environ['NODE_NAME'] = ''
44 reg_string = r"| POD: Unknown\s*|"
45 elif var == 'BUILD_TAG':
46 os.environ['BUILD_TAG'] = ''
47 reg_string = r"| BUILD TAG: None|"
49 with mock.patch('functest.cli.commands.cli_env.click.echo') \
51 self.cli_environ.show()
52 mock_click_echo.assert_called_with(RegexMatch(reg_string))
54 def test_show_ci_installer_type_ko(self, *args):
55 self._test_show_missing_env_var('INSTALLER_TYPE', *args)
57 def test_show_missing_ci_scenario(self, *args):
58 self._test_show_missing_env_var('SCENARIO', *args)
60 def test_show_missing_ci_node(self, *args):
61 self._test_show_missing_env_var('NODE', *args)
63 def test_show_missing_ci_build_tag(self, *args):
64 self._test_show_missing_env_var('BUILD_TAG', *args)
67 if __name__ == "__main__":
68 logging.disable(logging.CRITICAL)
69 unittest.main(verbosity=2)