test_check.py 2.9 KB

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