5 changed files with 92 additions and 9 deletions
@ -0,0 +1,28 @@
|
||||
from unittest.mock import patch |
||||
|
||||
import pytest |
||||
|
||||
from minitor.main import Alert |
||||
from minitor.main import Monitor |
||||
|
||||
|
||||
class TestAlert(object): |
||||
|
||||
@pytest.fixture |
||||
def monitor(self): |
||||
return Monitor({ |
||||
'name': 'Dummy Monitor', |
||||
'command': ['echo', 'foo'], |
||||
}) |
||||
|
||||
@pytest.fixture |
||||
def echo_alert(self): |
||||
return Alert( |
||||
'log', |
||||
{'command': ['echo', '{monitor_name} has failed!']} |
||||
) |
||||
|
||||
def test_simple_alert(self, monitor, echo_alert): |
||||
with patch.object(echo_alert.logger, 'error') as mock_error: |
||||
echo_alert.alert(monitor) |
||||
mock_error.assert_called_once_with('Dummy Monitor has failed!') |
@ -0,0 +1,14 @@
|
||||
from minitor.main import call_output |
||||
|
||||
|
||||
class TestMinitor(object): |
||||
|
||||
def test_call_output(self): |
||||
# valid command should have result and no exception |
||||
output, ex = call_output(['echo', 'test']) |
||||
assert output == b'test' |
||||
assert ex is None |
||||
|
||||
output, ex = call_output(['ls', '--not-a-real-flag']) |
||||
assert output.startswith(b'ls: illegal option') |
||||
assert ex is not None |
Loading…
Reference in new issue