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 == 'INSTALLER_IP':
40 os.environ['INSTALLER_IP'] = ''
41 reg_string = r"| INSTALLER: \S+, Unknown\s*|"
42 elif var == 'SCENARIO':
43 os.environ['DEPLOY_SCENARIO'] = ''
44 reg_string = r"| SCENARIO: Unknown\s*|"
46 os.environ['NODE_NAME'] = ''
47 reg_string = r"| POD: Unknown\s*|"
48 elif var == 'BUILD_TAG':
49 os.environ['BUILD_TAG'] = ''
50 reg_string = r"| BUILD TAG: None|"
52 with mock.patch('functest.cli.commands.cli_env.click.echo') \
54 self.cli_environ.show()
55 mock_click_echo.assert_called_with(RegexMatch(reg_string))
57 def test_show_ci_installer_type_ko(self, *args):
58 self._test_show_missing_env_var('INSTALLER_TYPE', *args)
60 def test_show_ci_installer_ip_ko(self, *args):
61 self._test_show_missing_env_var('INSTALLER_IP', *args)
63 def test_show_missing_ci_scenario(self, *args):
64 self._test_show_missing_env_var('SCENARIO', *args)
66 def test_show_missing_ci_node(self, *args):
67 self._test_show_missing_env_var('NODE', *args)
69 def test_show_missing_ci_build_tag(self, *args):
70 self._test_show_missing_env_var('BUILD_TAG', *args)
73 if __name__ == "__main__":
74 logging.disable(logging.CRITICAL)
75 unittest.main(verbosity=2)