test_check.py 3.1 KB

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