daemon: Implement diagnostic test for daemon component

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2019-12-30 11:37:38 -05:00
1 parent 0d5493dae7
commit 9cc3ddea2c
3 files changed
+43 -4

No files matched your search

+21 -1
View File
@@ -41,9 +41,13 @@ def test_initialization():
assert daemon.component_id == 'test-daemon'
assert daemon.unit == 'test-unit'
assert not daemon.strict_check
assert daemon.listen_ports == []
daemon = Daemon('test-daemon', 'test-unit', strict_check=True)
listen_ports = [(345, 'tcp4'), (123, 'udp')]
daemon = Daemon('test-daemon', 'test-unit', strict_check=True,
listen_ports=listen_ports)
assert daemon.strict_check
assert daemon.listen_ports == listen_ports
@patch('plinth.action_utils.service_is_enabled')
@@ -88,6 +92,22 @@ def test_is_running(service_is_running, daemon):
assert not daemon.is_running()
@patch('plinth.action_utils.diagnose_port_listening')
def test_diagnose(diagnose_port_listening, daemon):
"""Test running diagnostics."""
def side_effect(port, kind):
return [f'test-result-{port}-{kind}', 'passed']
daemon = Daemon('test-daemon', 'test-unit', listen_ports=[(8273, 'tcp4'),
(345, 'udp')])
diagnose_port_listening.side_effect = side_effect
results = daemon.diagnose()
assert results == [['test-result-8273-tcp4', 'passed'],
['test-result-345-udp', 'passed']]
diagnose_port_listening.assert_has_calls(
[call(8273, 'tcp4'), call(345, 'udp')])
@patch('plinth.action_utils.service_is_running')
def test_app_is_running(service_is_running):
"""Test that checking whether app is running works."""