test_check.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from flexmock import flexmock
  2. from borgmatic.actions import check as module
  3. def test_run_check_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.check).should_receive('check_archives').once()
  7. flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2)
  8. check_arguments = flexmock(
  9. repository=None,
  10. progress=flexmock(),
  11. repair=flexmock(),
  12. only=flexmock(),
  13. force=flexmock(),
  14. )
  15. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  16. module.run_check(
  17. config_filename='test.yaml',
  18. repository={'path': 'repo'},
  19. config={'repositories': ['repo']},
  20. hook_context={},
  21. local_borg_version=None,
  22. check_arguments=check_arguments,
  23. global_arguments=global_arguments,
  24. local_path=None,
  25. remote_path=None,
  26. )
  27. def test_run_check_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.check).should_receive('check_archives').once()
  33. check_arguments = flexmock(
  34. repository=flexmock(),
  35. progress=flexmock(),
  36. repair=flexmock(),
  37. only=flexmock(),
  38. force=flexmock(),
  39. )
  40. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  41. module.run_check(
  42. config_filename='test.yaml',
  43. repository={'path': 'repo'},
  44. config={'repositories': ['repo']},
  45. hook_context={},
  46. local_borg_version=None,
  47. check_arguments=check_arguments,
  48. global_arguments=global_arguments,
  49. local_path=None,
  50. remote_path=None,
  51. )
  52. def test_run_check_bails_if_repository_does_not_match():
  53. flexmock(module.logger).answer = lambda message: None
  54. flexmock(module.borgmatic.config.validate).should_receive(
  55. 'repositories_match'
  56. ).once().and_return(False)
  57. flexmock(module.borgmatic.borg.check).should_receive('check_archives').never()
  58. check_arguments = flexmock(
  59. repository=flexmock(),
  60. progress=flexmock(),
  61. repair=flexmock(),
  62. only=flexmock(),
  63. force=flexmock(),
  64. )
  65. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  66. module.run_check(
  67. config_filename='test.yaml',
  68. repository={'path': 'repo'},
  69. config={'repositories': ['repo']},
  70. hook_context={},
  71. local_borg_version=None,
  72. check_arguments=check_arguments,
  73. global_arguments=global_arguments,
  74. local_path=None,
  75. remote_path=None,
  76. )