2019-11-07 19:08:44 +01:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.hooks import cronhub as module
|
|
|
|
|
|
|
|
|
2019-11-13 00:31:07 +01:00
|
|
|
def test_ping_monitor_rewrites_ping_url_for_start_state():
|
2019-11-07 19:08:44 +01:00
|
|
|
ping_url = 'https://example.com/start/abcdef'
|
2019-11-13 00:31:07 +01:00
|
|
|
flexmock(module.requests).should_receive('get').with_args('https://example.com/start/abcdef')
|
2019-11-07 19:08:44 +01:00
|
|
|
|
2020-01-23 00:10:47 +01:00
|
|
|
module.ping_monitor(
|
|
|
|
ping_url, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=False
|
|
|
|
)
|
2019-11-07 19:08:44 +01:00
|
|
|
|
|
|
|
|
2019-11-13 00:31:07 +01:00
|
|
|
def test_ping_monitor_rewrites_ping_url_and_state_for_start_state():
|
2019-11-07 19:08:44 +01:00
|
|
|
ping_url = 'https://example.com/ping/abcdef'
|
2019-11-13 00:31:07 +01:00
|
|
|
flexmock(module.requests).should_receive('get').with_args('https://example.com/start/abcdef')
|
2019-11-07 19:08:44 +01:00
|
|
|
|
2020-01-23 00:10:47 +01:00
|
|
|
module.ping_monitor(
|
|
|
|
ping_url, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=False
|
|
|
|
)
|
2019-11-07 19:08:44 +01:00
|
|
|
|
|
|
|
|
2019-11-13 00:31:07 +01:00
|
|
|
def test_ping_monitor_rewrites_ping_url_for_finish_state():
|
|
|
|
ping_url = 'https://example.com/start/abcdef'
|
|
|
|
flexmock(module.requests).should_receive('get').with_args('https://example.com/finish/abcdef')
|
|
|
|
|
2020-01-23 00:10:47 +01:00
|
|
|
module.ping_monitor(
|
|
|
|
ping_url, 'config.yaml', module.monitor.State.FINISH, monitoring_log_level=1, dry_run=False
|
|
|
|
)
|
2019-11-13 00:31:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_ping_monitor_rewrites_ping_url_for_fail_state():
|
|
|
|
ping_url = 'https://example.com/start/abcdef'
|
|
|
|
flexmock(module.requests).should_receive('get').with_args('https://example.com/fail/abcdef')
|
2019-11-07 19:08:44 +01:00
|
|
|
|
2020-01-23 00:10:47 +01:00
|
|
|
module.ping_monitor(
|
|
|
|
ping_url, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
|
|
|
)
|
2019-11-07 19:08:44 +01:00
|
|
|
|
|
|
|
|
2019-11-13 00:31:07 +01:00
|
|
|
def test_ping_monitor_dry_run_does_not_hit_ping_url():
|
2019-11-07 19:08:44 +01:00
|
|
|
ping_url = 'https://example.com'
|
|
|
|
flexmock(module.requests).should_receive('get').never()
|
|
|
|
|
2020-01-23 00:10:47 +01:00
|
|
|
module.ping_monitor(
|
|
|
|
ping_url, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=True
|
|
|
|
)
|