|
@@ -3,18 +3,10 @@ from flexmock import flexmock
|
|
|
from borgmatic.hooks.monitoring import healthchecks as module
|
|
|
|
|
|
|
|
|
-def mock_logger():
|
|
|
- logger = flexmock()
|
|
|
- logger.should_receive('addHandler')
|
|
|
- logger.should_receive('removeHandler')
|
|
|
- flexmock(module.logging).should_receive('getLogger').and_return(logger)
|
|
|
-
|
|
|
-
|
|
|
def test_initialize_monitor_creates_log_handler_with_ping_body_limit():
|
|
|
ping_body_limit = 100
|
|
|
monitoring_log_level = 1
|
|
|
|
|
|
- mock_logger()
|
|
|
flexmock(module.borgmatic.hooks.monitoring.logs).should_receive(
|
|
|
'Forgetful_buffering_handler'
|
|
|
).with_args(
|
|
@@ -22,6 +14,7 @@ def test_initialize_monitor_creates_log_handler_with_ping_body_limit():
|
|
|
ping_body_limit - len(module.borgmatic.hooks.monitoring.logs.PAYLOAD_TRUNCATION_INDICATOR),
|
|
|
monitoring_log_level,
|
|
|
).once()
|
|
|
+ flexmock(module.borgmatic.hooks.monitoring.logs).should_receive('add_handler')
|
|
|
|
|
|
module.initialize_monitor(
|
|
|
{'ping_body_limit': ping_body_limit}, {}, 'test.yaml', monitoring_log_level, dry_run=False
|
|
@@ -31,7 +24,6 @@ def test_initialize_monitor_creates_log_handler_with_ping_body_limit():
|
|
|
def test_initialize_monitor_creates_log_handler_with_default_ping_body_limit():
|
|
|
monitoring_log_level = 1
|
|
|
|
|
|
- mock_logger()
|
|
|
flexmock(module.borgmatic.hooks.monitoring.logs).should_receive(
|
|
|
'Forgetful_buffering_handler'
|
|
|
).with_args(
|
|
@@ -40,6 +32,7 @@ def test_initialize_monitor_creates_log_handler_with_default_ping_body_limit():
|
|
|
- len(module.borgmatic.hooks.monitoring.logs.PAYLOAD_TRUNCATION_INDICATOR),
|
|
|
monitoring_log_level,
|
|
|
).once()
|
|
|
+ flexmock(module.borgmatic.hooks.monitoring.logs).should_receive('add_handler')
|
|
|
|
|
|
module.initialize_monitor({}, {}, 'test.yaml', monitoring_log_level, dry_run=False)
|
|
|
|
|
@@ -48,10 +41,10 @@ def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
|
|
|
ping_body_limit = 0
|
|
|
monitoring_log_level = 1
|
|
|
|
|
|
- mock_logger()
|
|
|
flexmock(module.borgmatic.hooks.monitoring.logs).should_receive(
|
|
|
'Forgetful_buffering_handler'
|
|
|
).with_args(module.HANDLER_IDENTIFIER, ping_body_limit, monitoring_log_level).once()
|
|
|
+ flexmock(module.borgmatic.hooks.monitoring.logs).should_receive('add_handler')
|
|
|
|
|
|
module.initialize_monitor(
|
|
|
{'ping_body_limit': ping_body_limit}, {}, 'test.yaml', monitoring_log_level, dry_run=False
|
|
@@ -59,10 +52,10 @@ def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
|
|
|
|
|
|
|
|
|
def test_initialize_monitor_creates_log_handler_when_send_logs_true():
|
|
|
- mock_logger()
|
|
|
flexmock(module.borgmatic.hooks.monitoring.logs).should_receive(
|
|
|
'Forgetful_buffering_handler'
|
|
|
).once()
|
|
|
+ flexmock(module.borgmatic.hooks.monitoring.logs).should_receive('add_handler')
|
|
|
|
|
|
module.initialize_monitor(
|
|
|
{'send_logs': True}, {}, 'test.yaml', monitoring_log_level=1, dry_run=False
|
|
@@ -70,10 +63,10 @@ def test_initialize_monitor_creates_log_handler_when_send_logs_true():
|
|
|
|
|
|
|
|
|
def test_initialize_monitor_bails_when_send_logs_false():
|
|
|
- mock_logger()
|
|
|
flexmock(module.borgmatic.hooks.monitoring.logs).should_receive(
|
|
|
'Forgetful_buffering_handler'
|
|
|
).never()
|
|
|
+ flexmock(module.borgmatic.hooks.monitoring.logs).should_receive('add_handler')
|
|
|
|
|
|
module.initialize_monitor(
|
|
|
{'send_logs': False}, {}, 'test.yaml', monitoring_log_level=1, dry_run=False
|