test_check.py 3.1 KB

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