Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 1 | import os |
| 2 | |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 3 | from tests.test_base import CfgCheckerTestBase |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 4 | |
| 5 | |
| 6 | class TestEntrypoints(CfgCheckerTestBase): |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 7 | def setUp(self): |
| 8 | # force env type to salt |
| 9 | os.environ['MCP_TYPE_FORCE'] = 'SALT' |
| 10 | |
| 11 | def tearDown(self): |
| 12 | del os.environ['MCP_TYPE_FORCE'] |
| 13 | |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 14 | def test_entry_mcp_checker(self): |
| 15 | _module_name = 'cfg_checker.cfg_check' |
| 16 | with self.redirect_output(): |
| 17 | _msg, _m = self._safe_import_module(_module_name) |
| 18 | |
| 19 | self.assertEqual( |
| 20 | len(_msg), |
| 21 | 0, |
| 22 | "Error importing '{}': {}".format( |
| 23 | _module_name, |
| 24 | _msg |
| 25 | ) |
| 26 | ) |
| 27 | |
| 28 | with self.redirect_output(): |
| 29 | with self.assertRaises(SystemExit) as ep: |
| 30 | _m.cfg_check.config_check_entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 31 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 32 | self.assertEqual( |
| 33 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 34 | 1, |
| 35 | "mcp-checker has unexpected exit code: {}".format( |
| 36 | ep.exception.code |
| 37 | ) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 38 | ) |
| 39 | |
| 40 | def test_entry_packages(self): |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 41 | _module_name = 'cfg_checker.cli.packages' |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 42 | with self.redirect_output(): |
| 43 | _msg, _m = self._safe_import_module(_module_name) |
| 44 | |
| 45 | self.assertEqual( |
| 46 | len(_msg), |
| 47 | 0, |
| 48 | "Error importing '{}': {}".format( |
| 49 | _module_name, |
| 50 | _msg |
| 51 | ) |
| 52 | ) |
| 53 | |
| 54 | with self.redirect_output(): |
| 55 | with self.assertRaises(SystemExit) as ep: |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 56 | _m.cli.packages.entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 57 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 58 | self.assertEqual( |
| 59 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 60 | 1, |
| 61 | "packages has unexpected exit code: {}".format(ep.exception.code) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 62 | ) |
| 63 | |
| 64 | def test_entry_network(self): |
| 65 | _module_name = 'cfg_checker.cli.network' |
| 66 | with self.redirect_output(): |
| 67 | _msg, _m = self._safe_import_module(_module_name) |
| 68 | |
| 69 | self.assertEqual( |
| 70 | len(_msg), |
| 71 | 0, |
| 72 | "Error importing '{}': {}".format( |
| 73 | _module_name, |
| 74 | _msg |
| 75 | ) |
| 76 | ) |
| 77 | |
| 78 | with self.redirect_output(): |
| 79 | with self.assertRaises(SystemExit) as ep: |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 80 | _m.cli.network.entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 81 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 82 | self.assertEqual( |
| 83 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 84 | 1, |
| 85 | "network has unexpected exit code: {}".format(ep.exception.code) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 86 | ) |
| 87 | |
| 88 | def test_entry_reclass(self): |
| 89 | _module_name = 'cfg_checker.cli.reclass' |
| 90 | with self.redirect_output(): |
| 91 | _msg, _m = self._safe_import_module(_module_name) |
| 92 | |
| 93 | self.assertEqual( |
| 94 | len(_msg), |
| 95 | 0, |
| 96 | "Error importing '{}': {}".format( |
| 97 | _module_name, |
| 98 | _msg |
| 99 | ) |
| 100 | ) |
| 101 | |
| 102 | with self.redirect_output(): |
| 103 | with self.assertRaises(SystemExit) as ep: |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 104 | _m.cli.reclass.entrypoint() |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 105 | # empty run should return code 1 |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 106 | self.assertEqual( |
| 107 | ep.exception.code, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 108 | 1, |
| 109 | "reclass has unexpected exit code: {}".format(ep.exception.code) |
Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 110 | ) |