test_recreate.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. import logging
  2. import shlex
  3. from flexmock import flexmock
  4. from borgmatic.borg import recreate as module
  5. from ..test_verbosity import insert_logging_mock
  6. def insert_execute_command_mock(command, working_directory=None, borg_exit_codes=None):
  7. flexmock(module.borgmatic.borg.environment).should_receive('make_environment')
  8. flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
  9. full_command=command,
  10. output_log_level=module.logging.INFO,
  11. environment=None,
  12. working_directory=working_directory,
  13. borg_local_path=command[0],
  14. borg_exit_codes=borg_exit_codes,
  15. ).once()
  16. def test_recreate_archive_dry_run_skips_execution():
  17. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  18. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  19. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  20. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  21. flexmock(module.borgmatic.borg.flags).should_receive(
  22. 'make_repository_archive_flags'
  23. ).and_return(('repo::archive',))
  24. flexmock(module.borgmatic.execute).should_receive('execute_command').never()
  25. recreate_arguments = flexmock(
  26. repository=flexmock(),
  27. list=None,
  28. target=None,
  29. comment=None,
  30. timestamp=None,
  31. match_archives=None,
  32. )
  33. result = module.recreate_archive(
  34. repository='repo',
  35. archive='archive',
  36. config={},
  37. local_borg_version='1.2.3',
  38. recreate_arguments=recreate_arguments,
  39. global_arguments=flexmock(log_json=False, dry_run=True),
  40. local_path='borg',
  41. )
  42. assert result is None
  43. def test_recreate_calls_borg_with_required_flags():
  44. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  45. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  46. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  47. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  48. flexmock(module.borgmatic.borg.flags).should_receive(
  49. 'make_repository_archive_flags'
  50. ).and_return(('repo::archive',))
  51. insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
  52. module.recreate_archive(
  53. repository='repo',
  54. archive='archive',
  55. config={},
  56. local_borg_version='1.2.3',
  57. recreate_arguments=flexmock(
  58. list=None,
  59. target=None,
  60. comment=None,
  61. timestamp=None,
  62. match_archives=None,
  63. ),
  64. global_arguments=flexmock(dry_run=False, log_json=False),
  65. local_path='borg',
  66. remote_path=None,
  67. patterns=None,
  68. )
  69. def test_recreate_with_remote_path():
  70. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  71. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  72. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  73. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  74. flexmock(module.borgmatic.borg.flags).should_receive(
  75. 'make_repository_archive_flags'
  76. ).and_return(('repo::archive',))
  77. insert_execute_command_mock(('borg', 'recreate', '--remote-path', 'borg1', 'repo::archive'))
  78. module.recreate_archive(
  79. repository='repo',
  80. archive='archive',
  81. config={},
  82. local_borg_version='1.2.3',
  83. recreate_arguments=flexmock(
  84. list=None,
  85. target=None,
  86. comment=None,
  87. timestamp=None,
  88. match_archives=None,
  89. ),
  90. global_arguments=flexmock(dry_run=False, log_json=False),
  91. local_path='borg',
  92. remote_path='borg1',
  93. patterns=None,
  94. )
  95. def test_recreate_with_lock_wait():
  96. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  97. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  98. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  99. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  100. flexmock(module.borgmatic.borg.flags).should_receive(
  101. 'make_repository_archive_flags'
  102. ).and_return(('repo::archive',))
  103. insert_execute_command_mock(('borg', 'recreate', '--lock-wait', '5', 'repo::archive'))
  104. module.recreate_archive(
  105. repository='repo',
  106. archive='archive',
  107. config={'lock_wait': '5'},
  108. local_borg_version='1.2.3',
  109. recreate_arguments=flexmock(
  110. list=None,
  111. target=None,
  112. comment=None,
  113. timestamp=None,
  114. match_archives=None,
  115. ),
  116. global_arguments=flexmock(dry_run=False, log_json=False),
  117. local_path='borg',
  118. patterns=None,
  119. )
  120. def test_recreate_with_log_info():
  121. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  122. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  123. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  124. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  125. flexmock(module.borgmatic.borg.flags).should_receive(
  126. 'make_repository_archive_flags'
  127. ).and_return(('repo::archive',))
  128. insert_execute_command_mock(('borg', 'recreate', '--info', 'repo::archive'))
  129. insert_logging_mock(logging.INFO)
  130. module.recreate_archive(
  131. repository='repo',
  132. archive='archive',
  133. config={},
  134. local_borg_version='1.2.3',
  135. recreate_arguments=flexmock(
  136. list=None,
  137. target=None,
  138. comment=None,
  139. timestamp=None,
  140. match_archives=None,
  141. ),
  142. global_arguments=flexmock(dry_run=False, log_json=False),
  143. local_path='borg',
  144. patterns=None,
  145. )
  146. def test_recreate_with_log_debug():
  147. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  148. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  149. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  150. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  151. flexmock(module.borgmatic.borg.flags).should_receive(
  152. 'make_repository_archive_flags'
  153. ).and_return(('repo::archive',))
  154. insert_execute_command_mock(('borg', 'recreate', '--debug', '--show-rc', 'repo::archive'))
  155. insert_logging_mock(logging.DEBUG)
  156. module.recreate_archive(
  157. repository='repo',
  158. archive='archive',
  159. config={},
  160. local_borg_version='1.2.3',
  161. recreate_arguments=flexmock(
  162. list=None,
  163. target=None,
  164. comment=None,
  165. timestamp=None,
  166. match_archives=None,
  167. ),
  168. global_arguments=flexmock(dry_run=False, log_json=False),
  169. local_path='borg',
  170. patterns=None,
  171. )
  172. def test_recreate_with_log_json():
  173. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  174. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  175. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  176. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  177. flexmock(module.borgmatic.borg.flags).should_receive(
  178. 'make_repository_archive_flags'
  179. ).and_return(('repo::archive',))
  180. insert_execute_command_mock(('borg', 'recreate', '--log-json', 'repo::archive'))
  181. module.recreate_archive(
  182. repository='repo',
  183. archive='archive',
  184. config={},
  185. local_borg_version='1.2.3',
  186. recreate_arguments=flexmock(
  187. list=None,
  188. target=None,
  189. comment=None,
  190. timestamp=None,
  191. match_archives=None,
  192. ),
  193. global_arguments=flexmock(dry_run=False, log_json=True),
  194. local_path='borg',
  195. patterns=None,
  196. )
  197. def test_recreate_archive_favors_list_flag_over_config():
  198. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  199. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  200. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  201. flexmock(module.borgmatic.borg.flags).should_receive(
  202. 'make_repository_archive_flags'
  203. ).and_return(('repo::archive',))
  204. flexmock(module).should_receive('make_list_filter_flags').and_return('AME+-')
  205. insert_execute_command_mock(
  206. ('borg', 'recreate', '--list', '--filter', 'AME+-', 'repo::archive')
  207. )
  208. module.recreate_archive(
  209. repository='repo',
  210. archive='archive',
  211. config={'list_details': False},
  212. local_borg_version='1.2.3',
  213. recreate_arguments=flexmock(
  214. list=True,
  215. target=None,
  216. comment=None,
  217. timestamp=None,
  218. match_archives=None,
  219. ),
  220. global_arguments=flexmock(dry_run=False, log_json=False),
  221. local_path='borg',
  222. patterns=None,
  223. )
  224. def test_recreate_archive_defaults_to_list_config():
  225. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  226. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  227. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  228. flexmock(module.borgmatic.borg.flags).should_receive(
  229. 'make_repository_archive_flags'
  230. ).and_return(('repo::archive',))
  231. flexmock(module).should_receive('make_list_filter_flags').and_return('AME+-')
  232. insert_execute_command_mock(
  233. ('borg', 'recreate', '--list', '--filter', 'AME+-', 'repo::archive')
  234. )
  235. module.recreate_archive(
  236. repository='repo',
  237. archive='archive',
  238. config={'list_details': True},
  239. local_borg_version='1.2.3',
  240. recreate_arguments=flexmock(
  241. list=None,
  242. target=None,
  243. comment=None,
  244. timestamp=None,
  245. match_archives=None,
  246. ),
  247. global_arguments=flexmock(dry_run=False, log_json=False),
  248. local_path='borg',
  249. patterns=None,
  250. )
  251. def test_recreate_with_patterns_from_flag():
  252. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  253. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  254. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  255. flexmock(module.borgmatic.borg.flags).should_receive(
  256. 'make_repository_archive_flags'
  257. ).and_return(('repo::archive',))
  258. mock_patterns_file = flexmock(name='patterns_file')
  259. flexmock(module).should_receive('write_patterns_file').and_return(mock_patterns_file)
  260. insert_execute_command_mock(
  261. ('borg', 'recreate', '--patterns-from', 'patterns_file', 'repo::archive')
  262. )
  263. module.recreate_archive(
  264. repository='repo',
  265. archive='archive',
  266. config={},
  267. local_borg_version='1.2.3',
  268. recreate_arguments=flexmock(
  269. list=None,
  270. target=None,
  271. comment=None,
  272. timestamp=None,
  273. match_archives=None,
  274. ),
  275. global_arguments=flexmock(dry_run=False, log_json=False),
  276. local_path='borg',
  277. patterns=['pattern1', 'pattern2'],
  278. )
  279. def test_recreate_with_exclude_flags():
  280. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  281. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  282. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  283. flexmock(module.borgmatic.borg.flags).should_receive(
  284. 'make_repository_archive_flags'
  285. ).and_return(('repo::archive',))
  286. flexmock(module).should_receive('make_exclude_flags').and_return(('--exclude', 'pattern'))
  287. insert_execute_command_mock(('borg', 'recreate', '--exclude', 'pattern', 'repo::archive'))
  288. module.recreate_archive(
  289. repository='repo',
  290. archive='archive',
  291. config={'exclude_patterns': ['pattern']},
  292. local_borg_version='1.2.3',
  293. recreate_arguments=flexmock(
  294. list=None,
  295. target=None,
  296. comment=None,
  297. timestamp=None,
  298. match_archives=None,
  299. ),
  300. global_arguments=flexmock(dry_run=False, log_json=False),
  301. local_path='borg',
  302. patterns=None,
  303. )
  304. def test_recreate_with_target_flag():
  305. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  306. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  307. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  308. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  309. flexmock(module.borgmatic.borg.flags).should_receive(
  310. 'make_repository_archive_flags'
  311. ).and_return(('repo::archive',))
  312. insert_execute_command_mock(('borg', 'recreate', '--target', 'new-archive', 'repo::archive'))
  313. module.recreate_archive(
  314. repository='repo',
  315. archive='archive',
  316. config={},
  317. local_borg_version='1.2.3',
  318. recreate_arguments=flexmock(
  319. list=None,
  320. target='new-archive',
  321. comment=None,
  322. timestamp=None,
  323. match_archives=None,
  324. ),
  325. global_arguments=flexmock(dry_run=False, log_json=False),
  326. local_path='borg',
  327. patterns=None,
  328. )
  329. def test_recreate_with_comment_flag():
  330. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  331. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  332. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  333. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  334. flexmock(module.borgmatic.borg.flags).should_receive(
  335. 'make_repository_archive_flags'
  336. ).and_return(('repo::archive',))
  337. insert_execute_command_mock(
  338. ('borg', 'recreate', '--comment', shlex.quote('This is a test comment'), 'repo::archive')
  339. )
  340. module.recreate_archive(
  341. repository='repo',
  342. archive='archive',
  343. config={},
  344. local_borg_version='1.2.3',
  345. recreate_arguments=flexmock(
  346. list=None,
  347. target=None,
  348. comment='This is a test comment',
  349. timestamp=None,
  350. match_archives=None,
  351. ),
  352. global_arguments=flexmock(dry_run=False, log_json=False),
  353. local_path='borg',
  354. patterns=None,
  355. )
  356. def test_recreate_with_timestamp_flag():
  357. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  358. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  359. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  360. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  361. flexmock(module.borgmatic.borg.flags).should_receive(
  362. 'make_repository_archive_flags'
  363. ).and_return(('repo::archive',))
  364. insert_execute_command_mock(
  365. ('borg', 'recreate', '--timestamp', '2023-10-01T12:00:00', 'repo::archive')
  366. )
  367. module.recreate_archive(
  368. repository='repo',
  369. archive='archive',
  370. config={},
  371. local_borg_version='1.2.3',
  372. recreate_arguments=flexmock(
  373. list=None,
  374. target=None,
  375. comment=None,
  376. timestamp='2023-10-01T12:00:00',
  377. match_archives=None,
  378. ),
  379. global_arguments=flexmock(dry_run=False, log_json=False),
  380. local_path='borg',
  381. patterns=None,
  382. )
  383. def test_recreate_with_compression_flag():
  384. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  385. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  386. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  387. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  388. flexmock(module.borgmatic.borg.flags).should_receive(
  389. 'make_repository_archive_flags'
  390. ).and_return(('repo::archive',))
  391. insert_execute_command_mock(('borg', 'recreate', '--compression', 'lz4', 'repo::archive'))
  392. module.recreate_archive(
  393. repository='repo',
  394. archive='archive',
  395. config={'compression': 'lz4'},
  396. local_borg_version='1.2.3',
  397. recreate_arguments=flexmock(
  398. list=None,
  399. target=None,
  400. comment=None,
  401. timestamp=None,
  402. match_archives=None,
  403. ),
  404. global_arguments=flexmock(dry_run=False, log_json=False),
  405. local_path='borg',
  406. patterns=None,
  407. )
  408. def test_recreate_with_chunker_params_flag():
  409. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  410. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  411. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  412. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  413. flexmock(module.borgmatic.borg.flags).should_receive(
  414. 'make_repository_archive_flags'
  415. ).and_return(('repo::archive',))
  416. insert_execute_command_mock(
  417. ('borg', 'recreate', '--chunker-params', '19,23,21,4095', 'repo::archive')
  418. )
  419. module.recreate_archive(
  420. repository='repo',
  421. archive='archive',
  422. config={'chunker_params': '19,23,21,4095'},
  423. local_borg_version='1.2.3',
  424. recreate_arguments=flexmock(
  425. list=None,
  426. target=None,
  427. comment=None,
  428. timestamp=None,
  429. match_archives=None,
  430. ),
  431. global_arguments=flexmock(dry_run=False, log_json=False),
  432. local_path='borg',
  433. patterns=None,
  434. )
  435. def test_recreate_with_recompress_flag():
  436. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  437. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  438. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  439. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  440. flexmock(module.borgmatic.borg.flags).should_receive(
  441. 'make_repository_archive_flags'
  442. ).and_return(('repo::archive',))
  443. insert_execute_command_mock(('borg', 'recreate', '--recompress', 'always', 'repo::archive'))
  444. module.recreate_archive(
  445. repository='repo',
  446. archive='archive',
  447. config={'recompress': 'always'},
  448. local_borg_version='1.2.3',
  449. recreate_arguments=flexmock(
  450. list=None,
  451. target=None,
  452. comment=None,
  453. timestamp=None,
  454. match_archives=None,
  455. ),
  456. global_arguments=flexmock(dry_run=False, log_json=False),
  457. local_path='borg',
  458. patterns=None,
  459. )
  460. def test_recreate_with_match_archives_star():
  461. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  462. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  463. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  464. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  465. flexmock(module.borgmatic.borg.flags).should_receive(
  466. 'make_repository_archive_flags'
  467. ).and_return(('repo::archive',))
  468. insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
  469. module.recreate_archive(
  470. repository='repo',
  471. archive='archive',
  472. config={},
  473. local_borg_version='1.2.3',
  474. recreate_arguments=flexmock(
  475. list=None,
  476. target=None,
  477. comment=None,
  478. timestamp=None,
  479. match_archives='*',
  480. ),
  481. global_arguments=flexmock(dry_run=False, log_json=False),
  482. local_path='borg',
  483. patterns=None,
  484. )
  485. def test_recreate_with_match_archives_regex():
  486. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  487. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  488. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  489. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  490. flexmock(module.borgmatic.borg.flags).should_receive(
  491. 'make_repository_archive_flags'
  492. ).and_return(('repo::archive',))
  493. insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
  494. module.recreate_archive(
  495. repository='repo',
  496. archive='archive',
  497. config={},
  498. local_borg_version='1.2.3',
  499. recreate_arguments=flexmock(
  500. list=None,
  501. target=None,
  502. comment=None,
  503. timestamp=None,
  504. match_archives='re:.*',
  505. ),
  506. global_arguments=flexmock(dry_run=False, log_json=False),
  507. local_path='borg',
  508. patterns=None,
  509. )
  510. def test_recreate_with_match_archives_shell():
  511. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  512. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  513. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  514. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  515. flexmock(module.borgmatic.borg.flags).should_receive(
  516. 'make_repository_archive_flags'
  517. ).and_return(('repo::archive',))
  518. insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
  519. module.recreate_archive(
  520. repository='repo',
  521. archive='archive',
  522. config={},
  523. local_borg_version='1.2.3',
  524. recreate_arguments=flexmock(
  525. list=None,
  526. target=None,
  527. comment=None,
  528. timestamp=None,
  529. match_archives='sh:*',
  530. ),
  531. global_arguments=flexmock(dry_run=False, log_json=False),
  532. local_path='borg',
  533. patterns=None,
  534. )
  535. def test_recreate_with_glob_archives_flag():
  536. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  537. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  538. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  539. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(
  540. ('--glob-archives', 'foo-*')
  541. )
  542. flexmock(module.borgmatic.borg.flags).should_receive(
  543. 'make_repository_archive_flags'
  544. ).and_return(('repo::archive',))
  545. insert_execute_command_mock(('borg', 'recreate', '--glob-archives', 'foo-*', 'repo::archive'))
  546. module.recreate_archive(
  547. repository='repo',
  548. archive='archive',
  549. config={},
  550. local_borg_version='1.2.3',
  551. recreate_arguments=flexmock(
  552. list=None,
  553. target=None,
  554. comment=None,
  555. timestamp=None,
  556. match_archives='foo-*',
  557. ),
  558. global_arguments=flexmock(dry_run=False, log_json=False),
  559. local_path='borg',
  560. patterns=None,
  561. )
  562. def test_recreate_with_match_archives_flag():
  563. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  564. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  565. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  566. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(
  567. ('--match-archives', 'sh:foo-*')
  568. )
  569. flexmock(module.borgmatic.borg.flags).should_receive(
  570. 'make_repository_archive_flags'
  571. ).and_return(('--repo', 'repo', 'archive'))
  572. insert_execute_command_mock(
  573. ('borg', 'recreate', '--match-archives', 'sh:foo-*', '--repo', 'repo', 'archive')
  574. )
  575. module.recreate_archive(
  576. repository='repo',
  577. archive='archive',
  578. config={},
  579. local_borg_version='2.0.0b3',
  580. recreate_arguments=flexmock(
  581. list=None,
  582. target=None,
  583. comment=None,
  584. timestamp=None,
  585. match_archives='sh:foo-*',
  586. ),
  587. global_arguments=flexmock(dry_run=False, log_json=False),
  588. local_path='borg',
  589. patterns=None,
  590. )