Skip to content

Commit ee4a13f

Browse files
committed
[squash] Add add unittests
1 parent 592a1f4 commit ee4a13f

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

check_monit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def print_output(status, count_ok, count_all, items):
7272
for item in items:
7373
s = "OK" if item.get('status') == 0 else "CRITICAL"
7474
print(' \\_ [{0}]: {1}'.format(s, item.get('name', 'No Name')))
75-
print(' ' + item.get('output', 'None'))
75+
print(' {}' .format(item.get('output', 'None')))
7676

7777
def get_service_output(service_type, element):
7878
# Service Type Filesystem

test_check_monit.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ def test_return_plugin(self, mock_print):
6464

6565
mock_print.assert_has_calls(calls)
6666

67+
@mock.patch('builtins.print')
68+
def test_return_plugin_with_no_output(self, mock_print):
69+
actual = print_output(1, 2, 3, [{'name': 'foo', 'output': None, 'status': 1}])
70+
71+
calls = [mock.call('[WARNING]: Monit Service Status 2/3'),
72+
mock.call(' \\_ [CRITICAL]: foo'),
73+
mock.call(' None')]
74+
75+
mock_print.assert_has_calls(calls)
76+
77+
actual = print_output(1, 2, 3, [{'name': 'foo', 'status': 1}])
78+
79+
calls = [mock.call('[WARNING]: Monit Service Status 2/3'),
80+
mock.call(' \\_ [CRITICAL]: foo'),
81+
mock.call(' None')]
82+
83+
mock_print.assert_has_calls(calls)
84+
6785
class MainTesting(unittest.TestCase):
6886

6987
@mock.patch('builtins.print')

0 commit comments

Comments
 (0)