add unit tests for tunnel and subnet

This commit is contained in:
Mike Kinney
2021-12-30 20:04:32 -08:00
parent 50523ec1b1
commit 3f307880f9
2 changed files with 43 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import sys
import os
import re
import logging
import platform
from unittest.mock import patch, MagicMock
import pytest
@@ -1692,3 +1693,42 @@ def test_tunnel_no_args(capsys, reset_globals):
assert pytest_wrapped_e.value.code == 1
_, err = capsys.readouterr()
assert re.search(r'usage: ', err, re.MULTILINE)
@pytest.mark.unit
@patch('platform.system')
def test_tunnel_tunnel_arg(mock_platform_system, capsys, reset_globals):
"""Test tunnel with tunnel arg (act like we are on a linux system)"""
a_mock = MagicMock()
a_mock.return_value = 'Linux'
mock_platform_system.side_effect = a_mock
sys.argv = ['', '--tunnel']
Globals.getInstance().set_args(sys.argv)
print(f'platform.system():{platform.system()}')
with pytest.raises(SystemExit) as pytest_wrapped_e:
tunnelMain()
mock_platform_system.assert_called()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
_, err = capsys.readouterr()
assert not re.search(r'usage: ', err, re.MULTILINE)
@pytest.mark.unit
@patch('platform.system')
def test_tunnel_subnet_arg(mock_platform_system, capsys, reset_globals):
"""Test tunnel with subnet arg (act like we are on a linux system)"""
a_mock = MagicMock()
a_mock.return_value = 'Linux'
mock_platform_system.side_effect = a_mock
sys.argv = ['', '--subnet', 'foo']
Globals.getInstance().set_args(sys.argv)
print(f'platform.system():{platform.system()}')
with pytest.raises(SystemExit) as pytest_wrapped_e:
tunnelMain()
mock_platform_system.assert_called()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
out, err = capsys.readouterr()
assert not re.search(r'usage: ', err, re.MULTILINE)
assert re.search(r'Warning: No Meshtastic devices detected', out, re.MULTILINE)