Add additional test coverage for credential tag (#966).

This commit is contained in:
Dan Helfman
2025-02-10 09:52:07 -08:00
parent 775385e688
commit 73fe29b055
4 changed files with 76 additions and 0 deletions
+18
View File
@@ -309,6 +309,24 @@ def test_ping_monitor_with_connection_error_logs_warning():
)
def test_ping_monitor_with_credential_error_logs_warning():
hook_config = {'topic': topic}
flexmock(module.borgmatic.hooks.credential.tag).should_receive('resolve_credential').and_raise(
ValueError
)
flexmock(module.requests).should_receive('post').never()
flexmock(module.logger).should_receive('warning').once()
module.ping_monitor(
hook_config,
{},
'config.yaml',
borgmatic.hooks.monitoring.monitor.State.FAIL,
monitoring_log_level=1,
dry_run=False,
)
def test_ping_monitor_with_other_error_logs_warning():
hook_config = {'topic': topic}
flexmock(module.borgmatic.hooks.credential.tag).should_receive(
@@ -86,6 +86,23 @@ def test_ping_monitor_with_connection_error_logs_warning():
)
def test_ping_monitor_with_credential_error_logs_warning():
flexmock(module.borgmatic.hooks.credential.tag).should_receive('resolve_credential').and_raise(
ValueError
)
flexmock(module.requests).should_receive('post').never()
flexmock(module.logger).should_receive('warning')
module.ping_monitor(
{'integration_key': 'abc123'},
{},
'config.yaml',
module.monitor.State.FAIL,
monitoring_log_level=1,
dry_run=False,
)
def test_ping_monitor_with_other_error_logs_warning():
response = flexmock(ok=False)
flexmock(module.borgmatic.hooks.credential.tag).should_receive(
@@ -562,3 +562,25 @@ def test_ping_monitor_push_post_error_bails():
monitoring_log_level=1,
dry_run=False,
)
def test_ping_monitor_credential_error_bails():
hook_config = hook_config = {
'token': 'ksdjfwoweijfvwoeifvjmwghagy92',
'user': '983hfe0of902lkjfa2amanfgui',
}
flexmock(module.borgmatic.hooks.credential.tag).should_receive('resolve_credential').and_raise(
ValueError
)
flexmock(module.requests).should_receive('post').never()
flexmock(module.logger).should_receive('warning').once()
module.ping_monitor(
hook_config,
{},
'config.yaml',
borgmatic.hooks.monitoring.monitor.State.FAIL,
monitoring_log_level=1,
dry_run=False,
)
@@ -520,3 +520,22 @@ def test_ping_monitor_config_itemid_with_username_password_auth_data_and_push_po
monitoring_log_level=1,
dry_run=False,
)
def test_ping_monitor_with_credential_error_bails():
hook_config = {'server': SERVER, 'itemid': ITEMID, 'username': USERNAME, 'password': PASSWORD}
flexmock(module.borgmatic.hooks.credential.tag).should_receive('resolve_credential').and_raise(
ValueError
)
flexmock(module.requests).should_receive('post').never()
flexmock(module.logger).should_receive('warning').once()
module.ping_monitor(
hook_config,
{},
'config.yaml',
borgmatic.hooks.monitoring.monitor.State.FAIL,
monitoring_log_level=1,
dry_run=False,
)