test_compact.py 2.9 KB

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