blob: 7c420d505445ec6287d996fcd96813bff46750e6 [file] [log] [blame]
Alex9a4ad212020-10-01 18:04:25 -05001import os
2
Alex3bc95f62020-03-05 17:00:04 -06003from tests.test_base import CfgCheckerTestBase
Alex265f45e2019-04-23 18:51:23 -05004
5
6class TestEntrypoints(CfgCheckerTestBase):
Alex9a4ad212020-10-01 18:04:25 -05007 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
Alex265f45e2019-04-23 18:51:23 -050014 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()
Alexcf91b182019-05-31 11:57:07 -050031 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -050032 self.assertEqual(
33 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -050034 1,
35 "mcp-checker has unexpected exit code: {}".format(
36 ep.exception.code
37 )
Alex265f45e2019-04-23 18:51:23 -050038 )
39
40 def test_entry_packages(self):
Alexbab1efe2019-04-23 18:51:23 -050041 _module_name = 'cfg_checker.cli.packages'
Alex265f45e2019-04-23 18:51:23 -050042 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:
Alexbab1efe2019-04-23 18:51:23 -050056 _m.cli.packages.entrypoint()
Alexcf91b182019-05-31 11:57:07 -050057 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -050058 self.assertEqual(
59 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -050060 1,
61 "packages has unexpected exit code: {}".format(ep.exception.code)
Alex265f45e2019-04-23 18:51:23 -050062 )
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:
Alexbab1efe2019-04-23 18:51:23 -050080 _m.cli.network.entrypoint()
Alexcf91b182019-05-31 11:57:07 -050081 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -050082 self.assertEqual(
83 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -050084 1,
85 "network has unexpected exit code: {}".format(ep.exception.code)
Alex265f45e2019-04-23 18:51:23 -050086 )
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:
Alexbab1efe2019-04-23 18:51:23 -0500104 _m.cli.reclass.entrypoint()
Alexcf91b182019-05-31 11:57:07 -0500105 # empty run should return code 1
Alex265f45e2019-04-23 18:51:23 -0500106 self.assertEqual(
107 ep.exception.code,
Alexcf91b182019-05-31 11:57:07 -0500108 1,
109 "reclass has unexpected exit code: {}".format(ep.exception.code)
Alex265f45e2019-04-23 18:51:23 -0500110 )