test_prune.py 2.5 KB

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