2
0

test_cronhub.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from flexmock import flexmock
  2. from borgmatic.hooks import cronhub as module
  3. def test_ping_monitor_rewrites_ping_url_for_start_state():
  4. hook_config = {'ping_url': 'https://example.com/start/abcdef'}
  5. flexmock(module.requests).should_receive('get').with_args('https://example.com/start/abcdef')
  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_rewrites_ping_url_and_state_for_start_state():
  14. hook_config = {'ping_url': 'https://example.com/ping/abcdef'}
  15. flexmock(module.requests).should_receive('get').with_args('https://example.com/start/abcdef')
  16. module.ping_monitor(
  17. hook_config,
  18. 'config.yaml',
  19. module.monitor.State.START,
  20. monitoring_log_level=1,
  21. dry_run=False,
  22. )
  23. def test_ping_monitor_rewrites_ping_url_for_finish_state():
  24. hook_config = {'ping_url': 'https://example.com/start/abcdef'}
  25. flexmock(module.requests).should_receive('get').with_args('https://example.com/finish/abcdef')
  26. module.ping_monitor(
  27. hook_config,
  28. 'config.yaml',
  29. module.monitor.State.FINISH,
  30. monitoring_log_level=1,
  31. dry_run=False,
  32. )
  33. def test_ping_monitor_rewrites_ping_url_for_fail_state():
  34. hook_config = {'ping_url': 'https://example.com/start/abcdef'}
  35. flexmock(module.requests).should_receive('get').with_args('https://example.com/fail/abcdef')
  36. module.ping_monitor(
  37. hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
  38. )
  39. def test_ping_monitor_dry_run_does_not_hit_ping_url():
  40. hook_config = {'ping_url': 'https://example.com'}
  41. flexmock(module.requests).should_receive('get').never()
  42. module.ping_monitor(
  43. hook_config, 'config.yaml', module.monitor.State.START, monitoring_log_level=1, dry_run=True
  44. )
  45. def test_ping_monitor_with_connection_error_does_not_raise():
  46. hook_config = {'ping_url': 'https://example.com/start/abcdef'}
  47. flexmock(module.requests).should_receive('get').and_raise(
  48. module.requests.exceptions.ConnectionError
  49. )
  50. module.ping_monitor(
  51. hook_config,
  52. 'config.yaml',
  53. module.monitor.State.START,
  54. monitoring_log_level=1,
  55. dry_run=False,
  56. )