test_compact.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from flexmock import flexmock
  2. from borgmatic.actions import compact as module
  3. def test_compact_actions_calls_hooks_for_configured_repository():
  4. flexmock(module.logger).answer = lambda message: None
  5. flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
  6. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never()
  7. flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').once()
  8. flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2)
  9. compact_arguments = flexmock(
  10. repository=None, progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock()
  11. )
  12. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  13. module.run_compact(
  14. config_filename='test.yaml',
  15. repository={'path': 'repo'},
  16. config={},
  17. hook_context={},
  18. local_borg_version=None,
  19. compact_arguments=compact_arguments,
  20. global_arguments=global_arguments,
  21. dry_run_label='',
  22. local_path=None,
  23. remote_path=None,
  24. )
  25. def test_compact_runs_with_selected_repository():
  26. flexmock(module.logger).answer = lambda message: None
  27. flexmock(module.borgmatic.config.validate).should_receive(
  28. 'repositories_match'
  29. ).once().and_return(True)
  30. flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
  31. flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').once()
  32. compact_arguments = flexmock(
  33. repository=flexmock(), progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock()
  34. )
  35. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  36. module.run_compact(
  37. config_filename='test.yaml',
  38. repository={'path': 'repo'},
  39. config={},
  40. hook_context={},
  41. local_borg_version=None,
  42. compact_arguments=compact_arguments,
  43. global_arguments=global_arguments,
  44. dry_run_label='',
  45. local_path=None,
  46. remote_path=None,
  47. )
  48. def test_compact_bails_if_repository_does_not_match():
  49. flexmock(module.logger).answer = lambda message: None
  50. flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
  51. flexmock(module.borgmatic.config.validate).should_receive(
  52. 'repositories_match'
  53. ).once().and_return(False)
  54. flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').never()
  55. compact_arguments = flexmock(
  56. repository=flexmock(), progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock()
  57. )
  58. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  59. module.run_compact(
  60. config_filename='test.yaml',
  61. repository={'path': 'repo'},
  62. config={},
  63. hook_context={},
  64. local_borg_version=None,
  65. compact_arguments=compact_arguments,
  66. global_arguments=global_arguments,
  67. dry_run_label='',
  68. local_path=None,
  69. remote_path=None,
  70. )