2019-11-01 18:33:15 +00:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.hooks import cronitor as module
|
|
|
|
|
|
|
|
|
2019-11-12 23:31:07 +00:00
|
|
|
def test_ping_monitor_hits_ping_url_for_start_state():
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config = {'ping_url': 'https://example.com'}
|
|
|
|
flexmock(module.requests).should_receive('get').with_args('https://example.com/run')
|
2019-11-01 18:33:15 +00:00
|
|
|
|
2020-01-22 23:10:47 +00:00
|
|
|
module.ping_monitor(
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config,
|
|
|
|
'config.yaml',
|
|
|
|
module.monitor.State.START,
|
|
|
|
monitoring_log_level=1,
|
|
|
|
dry_run=False,
|
2020-01-22 23:10:47 +00:00
|
|
|
)
|
2019-11-01 18:33:15 +00:00
|
|
|
|
|
|
|
|
2019-11-12 23:31:07 +00:00
|
|
|
def test_ping_monitor_hits_ping_url_for_finish_state():
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config = {'ping_url': 'https://example.com'}
|
|
|
|
flexmock(module.requests).should_receive('get').with_args('https://example.com/complete')
|
2019-11-12 23:31:07 +00:00
|
|
|
|
2020-01-22 23:10:47 +00:00
|
|
|
module.ping_monitor(
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config,
|
|
|
|
'config.yaml',
|
|
|
|
module.monitor.State.FINISH,
|
|
|
|
monitoring_log_level=1,
|
|
|
|
dry_run=False,
|
2020-01-22 23:10:47 +00:00
|
|
|
)
|
2019-11-12 23:31:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_ping_monitor_hits_ping_url_for_fail_state():
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config = {'ping_url': 'https://example.com'}
|
|
|
|
flexmock(module.requests).should_receive('get').with_args('https://example.com/fail')
|
2019-11-01 18:33:15 +00:00
|
|
|
|
2020-01-22 23:10:47 +00:00
|
|
|
module.ping_monitor(
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
2020-01-22 23:10:47 +00:00
|
|
|
)
|
2019-11-07 18:08:44 +00:00
|
|
|
|
|
|
|
|
2019-11-12 23:31:07 +00:00
|
|
|
def test_ping_monitor_dry_run_does_not_hit_ping_url():
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config = {'ping_url': 'https://example.com'}
|
2019-11-07 18:08:44 +00:00
|
|
|
flexmock(module.requests).should_receive('get').never()
|
|
|
|
|
2020-01-22 23:10:47 +00:00
|
|
|
module.ping_monitor(
|
2022-05-24 04:02:10 +01:00
|
|
|
hook_config, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=True
|
2020-01-22 23:10:47 +00:00
|
|
|
)
|
2022-05-24 23:50:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_ping_monitor_with_connection_error_does_not_raise():
|
|
|
|
hook_config = {'ping_url': 'https://example.com'}
|
|
|
|
flexmock(module.requests).should_receive('get').and_raise(
|
|
|
|
module.requests.exceptions.ConnectionError
|
|
|
|
)
|
|
|
|
|
|
|
|
module.ping_monitor(
|
|
|
|
hook_config,
|
|
|
|
'config.yaml',
|
|
|
|
module.monitor.State.START,
|
|
|
|
monitoring_log_level=1,
|
|
|
|
dry_run=False,
|
|
|
|
)
|