test_compact.py 3.1 KB

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