test_compact.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. compact_arguments = flexmock(
  9. repository=None, progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock()
  10. )
  11. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  12. module.run_compact(
  13. config_filename='test.yaml',
  14. repository={'path': 'repo'},
  15. config={},
  16. local_borg_version=None,
  17. compact_arguments=compact_arguments,
  18. global_arguments=global_arguments,
  19. dry_run_label='',
  20. local_path=None,
  21. remote_path=None,
  22. )
  23. def test_compact_runs_with_selected_repository():
  24. flexmock(module.logger).answer = lambda message: None
  25. flexmock(module.borgmatic.config.validate).should_receive(
  26. 'repositories_match'
  27. ).once().and_return(True)
  28. flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
  29. flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').once()
  30. compact_arguments = flexmock(
  31. repository=flexmock(), progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock()
  32. )
  33. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  34. module.run_compact(
  35. config_filename='test.yaml',
  36. repository={'path': 'repo'},
  37. config={},
  38. local_borg_version=None,
  39. compact_arguments=compact_arguments,
  40. global_arguments=global_arguments,
  41. dry_run_label='',
  42. local_path=None,
  43. remote_path=None,
  44. )
  45. def test_compact_bails_if_repository_does_not_match():
  46. flexmock(module.logger).answer = lambda message: None
  47. flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
  48. flexmock(module.borgmatic.config.validate).should_receive(
  49. 'repositories_match'
  50. ).once().and_return(False)
  51. flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').never()
  52. compact_arguments = flexmock(
  53. repository=flexmock(), progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock()
  54. )
  55. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  56. module.run_compact(
  57. config_filename='test.yaml',
  58. repository={'path': 'repo'},
  59. config={},
  60. local_borg_version=None,
  61. compact_arguments=compact_arguments,
  62. global_arguments=global_arguments,
  63. dry_run_label='',
  64. local_path=None,
  65. remote_path=None,
  66. )