test_rinfo.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import rinfo as module
  4. from ..test_verbosity import insert_logging_mock
  5. def test_display_repository_info_calls_borg_with_parameters():
  6. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  7. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  8. flexmock(module.feature).should_receive('available').and_return(True)
  9. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  10. flexmock(module.environment).should_receive('make_environment')
  11. flexmock(module).should_receive('execute_command').with_args(
  12. ('borg', 'rinfo', '--repo', 'repo'),
  13. output_log_level=module.borgmatic.logger.ANSWER,
  14. borg_local_path='borg',
  15. extra_environment=None,
  16. )
  17. module.display_repository_info(
  18. repository_path='repo',
  19. storage_config={},
  20. local_borg_version='2.3.4',
  21. rinfo_arguments=flexmock(json=False),
  22. )
  23. def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_command():
  24. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  25. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  26. flexmock(module.feature).should_receive('available').and_return(False)
  27. flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
  28. flexmock(module.environment).should_receive('make_environment')
  29. flexmock(module).should_receive('execute_command').with_args(
  30. ('borg', 'info', 'repo'),
  31. output_log_level=module.borgmatic.logger.ANSWER,
  32. borg_local_path='borg',
  33. extra_environment=None,
  34. )
  35. module.display_repository_info(
  36. repository_path='repo',
  37. storage_config={},
  38. local_borg_version='2.3.4',
  39. rinfo_arguments=flexmock(json=False),
  40. )
  41. def test_display_repository_info_with_log_info_calls_borg_with_info_parameter():
  42. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  43. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  44. flexmock(module.feature).should_receive('available').and_return(True)
  45. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  46. flexmock(module.environment).should_receive('make_environment')
  47. flexmock(module).should_receive('execute_command').with_args(
  48. ('borg', 'rinfo', '--info', '--repo', 'repo'),
  49. output_log_level=module.borgmatic.logger.ANSWER,
  50. borg_local_path='borg',
  51. extra_environment=None,
  52. )
  53. insert_logging_mock(logging.INFO)
  54. module.display_repository_info(
  55. repository_path='repo',
  56. storage_config={},
  57. local_borg_version='2.3.4',
  58. rinfo_arguments=flexmock(json=False),
  59. )
  60. def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_output():
  61. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  62. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  63. flexmock(module.feature).should_receive('available').and_return(True)
  64. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  65. flexmock(module.environment).should_receive('make_environment')
  66. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  67. ('borg', 'rinfo', '--json', '--repo', 'repo'), extra_environment=None,
  68. ).and_return('[]')
  69. insert_logging_mock(logging.INFO)
  70. json_output = module.display_repository_info(
  71. repository_path='repo',
  72. storage_config={},
  73. local_borg_version='2.3.4',
  74. rinfo_arguments=flexmock(json=True),
  75. )
  76. assert json_output == '[]'
  77. def test_display_repository_info_with_log_debug_calls_borg_with_debug_parameter():
  78. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  79. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  80. flexmock(module.feature).should_receive('available').and_return(True)
  81. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  82. flexmock(module.environment).should_receive('make_environment')
  83. flexmock(module).should_receive('execute_command').with_args(
  84. ('borg', 'rinfo', '--debug', '--show-rc', '--repo', 'repo'),
  85. output_log_level=module.borgmatic.logger.ANSWER,
  86. borg_local_path='borg',
  87. extra_environment=None,
  88. )
  89. insert_logging_mock(logging.DEBUG)
  90. module.display_repository_info(
  91. repository_path='repo',
  92. storage_config={},
  93. local_borg_version='2.3.4',
  94. rinfo_arguments=flexmock(json=False),
  95. )
  96. def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_output():
  97. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  98. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  99. flexmock(module.feature).should_receive('available').and_return(True)
  100. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  101. flexmock(module.environment).should_receive('make_environment')
  102. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  103. ('borg', 'rinfo', '--json', '--repo', 'repo'), extra_environment=None,
  104. ).and_return('[]')
  105. insert_logging_mock(logging.DEBUG)
  106. json_output = module.display_repository_info(
  107. repository_path='repo',
  108. storage_config={},
  109. local_borg_version='2.3.4',
  110. rinfo_arguments=flexmock(json=True),
  111. )
  112. assert json_output == '[]'
  113. def test_display_repository_info_with_json_calls_borg_with_json_parameter():
  114. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  115. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  116. flexmock(module.feature).should_receive('available').and_return(True)
  117. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  118. flexmock(module.environment).should_receive('make_environment')
  119. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  120. ('borg', 'rinfo', '--json', '--repo', 'repo'), extra_environment=None,
  121. ).and_return('[]')
  122. json_output = module.display_repository_info(
  123. repository_path='repo',
  124. storage_config={},
  125. local_borg_version='2.3.4',
  126. rinfo_arguments=flexmock(json=True),
  127. )
  128. assert json_output == '[]'
  129. def test_display_repository_info_with_local_path_calls_borg_via_local_path():
  130. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  131. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  132. flexmock(module.feature).should_receive('available').and_return(True)
  133. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  134. flexmock(module.environment).should_receive('make_environment')
  135. flexmock(module).should_receive('execute_command').with_args(
  136. ('borg1', 'rinfo', '--repo', 'repo'),
  137. output_log_level=module.borgmatic.logger.ANSWER,
  138. borg_local_path='borg1',
  139. extra_environment=None,
  140. )
  141. module.display_repository_info(
  142. repository_path='repo',
  143. storage_config={},
  144. local_borg_version='2.3.4',
  145. rinfo_arguments=flexmock(json=False),
  146. local_path='borg1',
  147. )
  148. def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_parameters():
  149. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  150. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  151. flexmock(module.feature).should_receive('available').and_return(True)
  152. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  153. flexmock(module.environment).should_receive('make_environment')
  154. flexmock(module).should_receive('execute_command').with_args(
  155. ('borg', 'rinfo', '--remote-path', 'borg1', '--repo', 'repo'),
  156. output_log_level=module.borgmatic.logger.ANSWER,
  157. borg_local_path='borg',
  158. extra_environment=None,
  159. )
  160. module.display_repository_info(
  161. repository_path='repo',
  162. storage_config={},
  163. local_borg_version='2.3.4',
  164. rinfo_arguments=flexmock(json=False),
  165. remote_path='borg1',
  166. )
  167. def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
  168. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  169. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  170. storage_config = {'lock_wait': 5}
  171. flexmock(module.feature).should_receive('available').and_return(True)
  172. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
  173. flexmock(module.environment).should_receive('make_environment')
  174. flexmock(module).should_receive('execute_command').with_args(
  175. ('borg', 'rinfo', '--lock-wait', '5', '--repo', 'repo'),
  176. output_log_level=module.borgmatic.logger.ANSWER,
  177. borg_local_path='borg',
  178. extra_environment=None,
  179. )
  180. module.display_repository_info(
  181. repository_path='repo',
  182. storage_config=storage_config,
  183. local_borg_version='2.3.4',
  184. rinfo_arguments=flexmock(json=False),
  185. )