2019-06-12 22:09:04 +02:00
|
|
|
import logging
|
|
|
|
|
2017-10-26 06:38:27 +02:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
2019-06-13 19:09:16 +02:00
|
|
|
from borgmatic import hook as module
|
2017-10-26 06:38:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_execute_hook_invokes_each_command():
|
2019-06-12 22:09:04 +02:00
|
|
|
flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
|
[':'], output_log_level=logging.WARNING, shell=True
|
|
|
|
).once()
|
2017-10-26 06:38:27 +02:00
|
|
|
|
2019-05-08 01:06:31 +02:00
|
|
|
module.execute_hook([':'], 'config.yaml', 'pre-backup', dry_run=False)
|
2017-10-26 07:32:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_execute_hook_with_multiple_commands_invokes_each_command():
|
2019-06-12 22:09:04 +02:00
|
|
|
flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
|
[':'], output_log_level=logging.WARNING, shell=True
|
|
|
|
).once()
|
|
|
|
flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
|
['true'], output_log_level=logging.WARNING, shell=True
|
|
|
|
).once()
|
2017-10-26 07:32:06 +02:00
|
|
|
|
2019-05-08 01:06:31 +02:00
|
|
|
module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_execute_hook_with_dry_run_skips_commands():
|
2019-06-12 22:09:04 +02:00
|
|
|
flexmock(module.execute).should_receive('execute_command').never()
|
2019-05-08 01:06:31 +02:00
|
|
|
|
|
|
|
module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=True)
|
2017-10-26 07:32:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_execute_hook_with_empty_commands_does_not_raise():
|
2019-05-08 01:06:31 +02:00
|
|
|
module.execute_hook([], 'config.yaml', 'post-backup', dry_run=False)
|
2019-06-13 19:14:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_execute_hook_on_error_logs_as_error():
|
|
|
|
flexmock(module.execute).should_receive('execute_command').with_args(
|
|
|
|
[':'], output_log_level=logging.ERROR, shell=True
|
|
|
|
).once()
|
|
|
|
|
|
|
|
module.execute_hook([':'], 'config.yaml', 'on-error', dry_run=False)
|