1from flexmock import flexmock
2
3from borgmatic.hooks import cronhub as module
4
5
6def test_ping_monitor_rewrites_ping_url_for_start_state():
7    ping_url = 'https://example.com/start/abcdef'
8    flexmock(module.requests).should_receive('get').with_args('https://example.com/start/abcdef')
9
10    module.ping_monitor(
11        ping_url, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=False
12    )
13
14
15def test_ping_monitor_rewrites_ping_url_and_state_for_start_state():
16    ping_url = 'https://example.com/ping/abcdef'
17    flexmock(module.requests).should_receive('get').with_args('https://example.com/start/abcdef')
18
19    module.ping_monitor(
20        ping_url, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=False
21    )
22
23
24def test_ping_monitor_rewrites_ping_url_for_finish_state():
25    ping_url = 'https://example.com/start/abcdef'
26    flexmock(module.requests).should_receive('get').with_args('https://example.com/finish/abcdef')
27
28    module.ping_monitor(
29        ping_url, 'config.yaml', module.monitor.State.FINISH, monitoring_log_level=1, dry_run=False
30    )
31
32
33def test_ping_monitor_rewrites_ping_url_for_fail_state():
34    ping_url = 'https://example.com/start/abcdef'
35    flexmock(module.requests).should_receive('get').with_args('https://example.com/fail/abcdef')
36
37    module.ping_monitor(
38        ping_url, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
39    )
40
41
42def test_ping_monitor_dry_run_does_not_hit_ping_url():
43    ping_url = 'https://example.com'
44    flexmock(module.requests).should_receive('get').never()
45
46    module.ping_monitor(
47        ping_url, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=True
48    )
49