test_rinfo.py 7.7 KB

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