test_hook.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic import hook as module
  4. def test_execute_hook_invokes_each_command():
  5. flexmock(module.execute).should_receive('execute_command').with_args(
  6. [':'], output_log_level=logging.WARNING, shell=True
  7. ).once()
  8. module.execute_hook([':'], 'config.yaml', 'pre-backup', dry_run=False)
  9. def test_execute_hook_with_multiple_commands_invokes_each_command():
  10. flexmock(module.execute).should_receive('execute_command').with_args(
  11. [':'], output_log_level=logging.WARNING, shell=True
  12. ).once()
  13. flexmock(module.execute).should_receive('execute_command').with_args(
  14. ['true'], output_log_level=logging.WARNING, shell=True
  15. ).once()
  16. module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=False)
  17. def test_execute_hook_with_dry_run_skips_commands():
  18. flexmock(module.execute).should_receive('execute_command').never()
  19. module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=True)
  20. def test_execute_hook_with_empty_commands_does_not_raise():
  21. module.execute_hook([], 'config.yaml', 'post-backup', dry_run=False)
  22. def test_execute_hook_on_error_logs_as_error():
  23. flexmock(module.execute).should_receive('execute_command').with_args(
  24. [':'], output_log_level=logging.ERROR, shell=True
  25. ).once()
  26. module.execute_hook([':'], 'config.yaml', 'on-error', dry_run=False)