test_prune.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from flexmock import flexmock
  2. from borgmatic.actions import prune as module
  3. def test_run_prune_calls_hooks_for_configured_repository():
  4. flexmock(module.logger).answer = lambda message: None
  5. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never()
  6. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').once()
  7. flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2)
  8. prune_arguments = flexmock(repository=None, stats=flexmock(), list_archives=flexmock())
  9. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  10. module.run_prune(
  11. config_filename='test.yaml',
  12. repository={'path': 'repo'},
  13. config={},
  14. hook_context={},
  15. local_borg_version=None,
  16. prune_arguments=prune_arguments,
  17. global_arguments=global_arguments,
  18. dry_run_label='',
  19. local_path=None,
  20. remote_path=None,
  21. )
  22. def test_run_prune_runs_with_selected_repository():
  23. flexmock(module.logger).answer = lambda message: None
  24. flexmock(module.borgmatic.config.validate).should_receive(
  25. 'repositories_match'
  26. ).once().and_return(True)
  27. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').once()
  28. prune_arguments = flexmock(repository=flexmock(), stats=flexmock(), list_archives=flexmock())
  29. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  30. module.run_prune(
  31. config_filename='test.yaml',
  32. repository={'path': 'repo'},
  33. config={},
  34. hook_context={},
  35. local_borg_version=None,
  36. prune_arguments=prune_arguments,
  37. global_arguments=global_arguments,
  38. dry_run_label='',
  39. local_path=None,
  40. remote_path=None,
  41. )
  42. def test_run_prune_bails_if_repository_does_not_match():
  43. flexmock(module.logger).answer = lambda message: None
  44. flexmock(module.borgmatic.config.validate).should_receive(
  45. 'repositories_match'
  46. ).once().and_return(False)
  47. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').never()
  48. prune_arguments = flexmock(repository=flexmock(), stats=flexmock(), list_archives=flexmock())
  49. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  50. module.run_prune(
  51. config_filename='test.yaml',
  52. repository='repo',
  53. config={},
  54. hook_context={},
  55. local_borg_version=None,
  56. prune_arguments=prune_arguments,
  57. global_arguments=global_arguments,
  58. dry_run_label='',
  59. local_path=None,
  60. remote_path=None,
  61. )