test_cronitor.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from flexmock import flexmock
  2. from borgmatic.hooks import cronitor as module
  3. def test_ping_monitor_hits_ping_url_for_start_state():
  4. hook_config = {'ping_url': 'https://example.com'}
  5. flexmock(module.requests).should_receive('get').with_args('https://example.com/run')
  6. module.ping_monitor(
  7. hook_config,
  8. 'config.yaml',
  9. module.monitor.State.START,
  10. monitoring_log_level=1,
  11. dry_run=False,
  12. )
  13. def test_ping_monitor_hits_ping_url_for_finish_state():
  14. hook_config = {'ping_url': 'https://example.com'}
  15. flexmock(module.requests).should_receive('get').with_args('https://example.com/complete')
  16. module.ping_monitor(
  17. hook_config,
  18. 'config.yaml',
  19. module.monitor.State.FINISH,
  20. monitoring_log_level=1,
  21. dry_run=False,
  22. )
  23. def test_ping_monitor_hits_ping_url_for_fail_state():
  24. hook_config = {'ping_url': 'https://example.com'}
  25. flexmock(module.requests).should_receive('get').with_args('https://example.com/fail')
  26. module.ping_monitor(
  27. hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
  28. )
  29. def test_ping_monitor_dry_run_does_not_hit_ping_url():
  30. hook_config = {'ping_url': 'https://example.com'}
  31. flexmock(module.requests).should_receive('get').never()
  32. module.ping_monitor(
  33. hook_config, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=True
  34. )
  35. def test_ping_monitor_with_connection_error_does_not_raise():
  36. hook_config = {'ping_url': 'https://example.com'}
  37. flexmock(module.requests).should_receive('get').and_raise(
  38. module.requests.exceptions.ConnectionError
  39. )
  40. module.ping_monitor(
  41. hook_config,
  42. 'config.yaml',
  43. module.monitor.State.START,
  44. monitoring_log_level=1,
  45. dry_run=False,
  46. )