From 3ab4b45041a26cf09ff7b991cb3650bd50a6a43f Mon Sep 17 00:00:00 2001 From: Antonio Fernandez Date: Wed, 13 Nov 2024 09:07:47 -0500 Subject: [PATCH] added test for early exit when state is not in config --- tests/unit/hooks/test_pushover.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unit/hooks/test_pushover.py b/tests/unit/hooks/test_pushover.py index 422acdbf..a62cd9d3 100644 --- a/tests/unit/hooks/test_pushover.py +++ b/tests/unit/hooks/test_pushover.py @@ -477,3 +477,32 @@ def test_ping_monitor_config_with_minimum_config_fail_state_backup_successfully_ monitoring_log_level=1, dry_run=True, ) + + +def test_ping_monitor_config_incorrect_state_exit_early(): + ''' + This test should exit early since the start state is not declared in the configuration. + ''' + hook_config = { + 'token': 'ksdjfwoweijfvwoeifvjmwghagy92', + 'user': '983hfe0of902lkjfa2amanfgui', + } + flexmock(module.logger).should_receive('warning').never() + flexmock(module.requests).should_receive('post').with_args( + 'https://api.pushover.net/1/messages.json', + headers={'Content-type': 'application/x-www-form-urlencoded'}, + data={ + 'token': 'ksdjfwoweijfvwoeifvjmwghagy92', + 'user': '983hfe0of902lkjfa2amanfgui', + 'message': 'start', + }, + ).and_return(flexmock(ok=True)).never() + + module.ping_monitor( + hook_config, + {}, + 'config.yaml', + borgmatic.hooks.monitor.State.START, + monitoring_log_level=1, + dry_run=True, + )