test_prune.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. storage={},
  14. retention={},
  15. hooks={},
  16. hook_context={},
  17. local_borg_version=None,
  18. prune_arguments=prune_arguments,
  19. global_arguments=global_arguments,
  20. dry_run_label='',
  21. local_path=None,
  22. remote_path=None,
  23. )
  24. def test_run_prune_runs_with_selected_repository():
  25. flexmock(module.logger).answer = lambda message: None
  26. flexmock(module.borgmatic.config.validate).should_receive(
  27. 'repositories_match'
  28. ).once().and_return(True)
  29. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').once()
  30. prune_arguments = flexmock(repository=flexmock(), stats=flexmock(), list_archives=flexmock())
  31. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  32. module.run_prune(
  33. config_filename='test.yaml',
  34. repository={'path': 'repo'},
  35. storage={},
  36. retention={},
  37. hooks={},
  38. hook_context={},
  39. local_borg_version=None,
  40. prune_arguments=prune_arguments,
  41. global_arguments=global_arguments,
  42. dry_run_label='',
  43. local_path=None,
  44. remote_path=None,
  45. )
  46. def test_run_prune_bails_if_repository_does_not_match():
  47. flexmock(module.logger).answer = lambda message: None
  48. flexmock(module.borgmatic.config.validate).should_receive(
  49. 'repositories_match'
  50. ).once().and_return(False)
  51. flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').never()
  52. prune_arguments = flexmock(repository=flexmock(), stats=flexmock(), list_archives=flexmock())
  53. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  54. module.run_prune(
  55. config_filename='test.yaml',
  56. repository='repo',
  57. storage={},
  58. retention={},
  59. hooks={},
  60. hook_context={},
  61. local_borg_version=None,
  62. prune_arguments=prune_arguments,
  63. global_arguments=global_arguments,
  64. dry_run_label='',
  65. local_path=None,
  66. remote_path=None,
  67. )