mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-03-08 05:31:58 +00:00
Adding REGEX to sample configuration and updating the unit tests.
This commit is contained in:
@@ -7,6 +7,8 @@ endpoint:
|
|||||||
status: 200
|
status: 200
|
||||||
- type: LATENCY
|
- type: LATENCY
|
||||||
threshold: 1
|
threshold: 1
|
||||||
|
- type: REGEX
|
||||||
|
regex: ".*<body>.*"
|
||||||
cachet:
|
cachet:
|
||||||
api_url: http://status.cachethq.io/api/v1/
|
api_url: http://status.cachethq.io/api/v1/
|
||||||
token: my_token
|
token: my_token
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class ConfigurationTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
assert len(self.configuration.data) == 3
|
assert len(self.configuration.data) == 3
|
||||||
assert len(self.configuration.expectations) == 2
|
assert len(self.configuration.expectations) == 3
|
||||||
|
|
||||||
def test_evaluate(self):
|
def test_evaluate(self):
|
||||||
def total_seconds():
|
def total_seconds():
|
||||||
@@ -31,6 +31,7 @@ class ConfigurationTest(unittest.TestCase):
|
|||||||
response.status_code = 200
|
response.status_code = 200
|
||||||
response.elapsed = mock.Mock()
|
response.elapsed = mock.Mock()
|
||||||
response.elapsed.total_seconds = total_seconds
|
response.elapsed.total_seconds = total_seconds
|
||||||
|
response.text = '<body>'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
sys.modules['requests'].request = request
|
sys.modules['requests'].request = request
|
||||||
@@ -47,6 +48,7 @@ class ConfigurationTest(unittest.TestCase):
|
|||||||
response.status_code = 400
|
response.status_code = 400
|
||||||
response.elapsed = mock.Mock()
|
response.elapsed = mock.Mock()
|
||||||
response.elapsed.total_seconds = total_seconds
|
response.elapsed.total_seconds = total_seconds
|
||||||
|
response.text = '<body>'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
sys.modules['requests'].request = request
|
sys.modules['requests'].request = request
|
||||||
|
|||||||
@@ -74,26 +74,26 @@ class HttpStatusTest(unittest.TestCase):
|
|||||||
|
|
||||||
class RegexTest(unittest.TestCase):
|
class RegexTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.expectation = Regex({'type': 'REGEX', 'regex': '.*(found stuff).*'})
|
self.expectation = Regex({'type': 'REGEX', 'regex': '.*(find stuff).*'})
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
assert self.expectation.regex == re.compile('.*(found stuff).*')
|
assert self.expectation.regex == re.compile('.*(find stuff).*')
|
||||||
|
|
||||||
def test_get_status_healthy(self):
|
def test_get_status_healthy(self):
|
||||||
request = mock.Mock()
|
request = mock.Mock()
|
||||||
request.text = 'We cound found stuff in this body.'
|
request.text = 'We could find stuff in this body.'
|
||||||
|
|
||||||
assert self.expectation.get_status(request) == 1
|
assert self.expectation.get_status(request) == 1
|
||||||
|
|
||||||
def test_get_status_unhealthy(self):
|
def test_get_status_unhealthy(self):
|
||||||
request = mock.Mock()
|
request = mock.Mock()
|
||||||
request.text = 'We will not find here'
|
request.text = 'We will not find it here'
|
||||||
|
|
||||||
assert self.expectation.get_status(request) == 3
|
assert self.expectation.get_status(request) == 3
|
||||||
|
|
||||||
def test_get_message(self):
|
def test_get_message(self):
|
||||||
request = mock.Mock()
|
request = mock.Mock()
|
||||||
request.text = 'We will not find here'
|
request.text = 'We will not find it here'
|
||||||
|
|
||||||
assert self.expectation.get_message(request) == ('Regex did not match '
|
assert self.expectation.get_message(request) == ('Regex did not match '
|
||||||
'anything in the body')
|
'anything in the body')
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import logging
|
|
||||||
import mock
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
@@ -35,11 +34,11 @@ class AgentTest(unittest.TestCase):
|
|||||||
|
|
||||||
class SchedulerTest(unittest.TestCase):
|
class SchedulerTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mock_configuration = sys.modules['cachet_url_monitor.configuration.Configuration']
|
self.mock_configuration = sys.modules[('cachet_url_monitor.configuration'
|
||||||
|
'.Configuration')]
|
||||||
self.scheduler = Scheduler('config.yml')
|
self.scheduler = Scheduler('config.yml')
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
#TODO(mtakaki|2016-05-01): We need more assertions in this test.
|
|
||||||
assert self.scheduler.stop == False
|
assert self.scheduler.stop == False
|
||||||
|
|
||||||
def test_start(self):
|
def test_start(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user