2
0

test_healthchecks.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.hooks.monitoring import healthchecks as module
  4. def test_destroy_monitor_removes_healthchecks_handler():
  5. logger = logging.getLogger()
  6. original_handlers = list(logger.handlers)
  7. # Don't mess with the actual log level because it can impact downstream tests.
  8. flexmock(logger).should_receive('setLevel')
  9. module.borgmatic.hooks.monitoring.logs.add_handler(
  10. module.borgmatic.hooks.monitoring.logs.Forgetful_buffering_handler(
  11. identifier=module.HANDLER_IDENTIFIER,
  12. byte_capacity=100,
  13. log_level=1,
  14. ),
  15. )
  16. module.destroy_monitor(
  17. hook_config=flexmock(),
  18. config=flexmock(),
  19. monitoring_log_level=1,
  20. dry_run=False,
  21. )
  22. assert logger.handlers == original_handlers
  23. def test_destroy_monitor_without_healthchecks_handler_does_not_raise():
  24. logger = logging.getLogger()
  25. original_handlers = list(logger.handlers)
  26. # Don't mess with the actual log level because it can impact downstream tests.
  27. flexmock(logger).should_receive('setLevel')
  28. module.destroy_monitor(
  29. hook_config=flexmock(),
  30. config=flexmock(),
  31. monitoring_log_level=1,
  32. dry_run=False,
  33. )
  34. assert logger.handlers == original_handlers