daemon: Move diagnosing using netcat to daemon module

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:54 -05:00
1 parent 97d8166f31
commit c617cecc02
4 files changed
+53 -29

No files matched your search

+24 -1
View File
@@ -24,7 +24,8 @@ from unittest.mock import Mock, call, patch
import pytest
from plinth.app import App, FollowerComponent
from plinth.daemon import Daemon, app_is_running, diagnose_port_listening
from plinth.daemon import (Daemon, app_is_running, diagnose_netcat,
diagnose_port_listening)
@pytest.fixture(name='daemon')
@@ -210,3 +211,25 @@ def test_diagnose_port_listening(connections):
assert diagnose_port_listening(3456, 'udp4')[1] == 'passed'
assert diagnose_port_listening(6789, 'udp4')[1] == 'passed'
assert diagnose_port_listening(5678, 'udp4')[1] == 'failed'
@patch('subprocess.Popen')
def test_diagnose_netcat(popen):
"""Test running diagnostic test using netcat."""
popen().returncode = 0
result = diagnose_netcat('test-host', 3300, input='test-input')
assert result == ['Connect to test-host:3300', 'passed']
assert popen.mock_calls[1][1] == (['nc', 'test-host', '3300'], )
assert popen.mock_calls[2] == call().communicate(input=b'test-input')
result = diagnose_netcat('test-host', 3300, input='test-input',
negate=True)
assert result == ['Cannot connect to test-host:3300', 'failed']
popen().returncode = 1
result = diagnose_netcat('test-host', 3300, input='test-input')
assert result == ['Connect to test-host:3300', 'failed']
result = diagnose_netcat('test-host', 3300, input='test-input',
negate=True)
assert result == ['Cannot connect to test-host:3300', 'passed']