test_borg.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import borg as module
  4. from ..test_verbosity import insert_logging_mock
  5. def test_run_arbitrary_borg_calls_borg_with_parameters():
  6. flexmock(module).should_receive('execute_command').with_args(
  7. ('borg', 'break-lock', 'repo'), output_log_level=logging.WARNING, borg_local_path='borg'
  8. )
  9. module.run_arbitrary_borg(
  10. repository='repo', storage_config={}, options=['break-lock'],
  11. )
  12. def test_run_arbitrary_borg_with_log_info_calls_borg_with_info_parameter():
  13. flexmock(module).should_receive('execute_command').with_args(
  14. ('borg', 'break-lock', 'repo', '--info'),
  15. output_log_level=logging.WARNING,
  16. borg_local_path='borg',
  17. )
  18. insert_logging_mock(logging.INFO)
  19. module.run_arbitrary_borg(
  20. repository='repo', storage_config={}, options=['break-lock'],
  21. )
  22. def test_run_arbitrary_borg_with_log_debug_calls_borg_with_debug_parameter():
  23. flexmock(module).should_receive('execute_command').with_args(
  24. ('borg', 'break-lock', 'repo', '--debug', '--show-rc'),
  25. output_log_level=logging.WARNING,
  26. borg_local_path='borg',
  27. )
  28. insert_logging_mock(logging.DEBUG)
  29. module.run_arbitrary_borg(
  30. repository='repo', storage_config={}, options=['break-lock'],
  31. )
  32. def test_run_arbitrary_borg_with_lock_wait_calls_borg_with_lock_wait_parameters():
  33. storage_config = {'lock_wait': 5}
  34. flexmock(module).should_receive('execute_command').with_args(
  35. ('borg', 'break-lock', 'repo', '--lock-wait', '5'),
  36. output_log_level=logging.WARNING,
  37. borg_local_path='borg',
  38. )
  39. module.run_arbitrary_borg(
  40. repository='repo', storage_config=storage_config, options=['break-lock'],
  41. )
  42. def test_run_arbitrary_borg_with_archive_calls_borg_with_archive_parameter():
  43. storage_config = {}
  44. flexmock(module).should_receive('execute_command').with_args(
  45. ('borg', 'break-lock', 'repo::archive'),
  46. output_log_level=logging.WARNING,
  47. borg_local_path='borg',
  48. )
  49. module.run_arbitrary_borg(
  50. repository='repo', storage_config=storage_config, options=['break-lock'], archive='archive',
  51. )
  52. def test_run_arbitrary_borg_with_local_path_calls_borg_via_local_path():
  53. flexmock(module).should_receive('execute_command').with_args(
  54. ('borg1', 'break-lock', 'repo'), output_log_level=logging.WARNING, borg_local_path='borg1'
  55. )
  56. module.run_arbitrary_borg(
  57. repository='repo', storage_config={}, options=['break-lock'], local_path='borg1',
  58. )
  59. def test_run_arbitrary_borg_with_remote_path_calls_borg_with_remote_path_parameters():
  60. flexmock(module).should_receive('execute_command').with_args(
  61. ('borg', 'break-lock', 'repo', '--remote-path', 'borg1'),
  62. output_log_level=logging.WARNING,
  63. borg_local_path='borg',
  64. )
  65. module.run_arbitrary_borg(
  66. repository='repo', storage_config={}, options=['break-lock'], remote_path='borg1',
  67. )
  68. def test_run_arbitrary_borg_passes_borg_specific_parameters_to_borg():
  69. flexmock(module).should_receive('execute_command').with_args(
  70. ('borg', 'list', 'repo', '--progress'),
  71. output_log_level=logging.WARNING,
  72. borg_local_path='borg',
  73. )
  74. module.run_arbitrary_borg(
  75. repository='repo', storage_config={}, options=['list', '--progress'],
  76. )
  77. def test_run_arbitrary_borg_omits_dash_dash_in_parameters_passed_to_borg():
  78. flexmock(module).should_receive('execute_command').with_args(
  79. ('borg', 'break-lock', 'repo'), output_log_level=logging.WARNING, borg_local_path='borg',
  80. )
  81. module.run_arbitrary_borg(
  82. repository='repo', storage_config={}, options=['--', 'break-lock'],
  83. )
  84. def test_run_arbitrary_borg_without_borg_specific_parameters_does_not_raise():
  85. flexmock(module).should_receive('execute_command').with_args(
  86. ('borg',), output_log_level=logging.WARNING, borg_local_path='borg',
  87. )
  88. module.run_arbitrary_borg(
  89. repository='repo', storage_config={}, options=[],
  90. )