test_recreate.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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_with_list_config_calls_borg_with_list_flag():
  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': True},
  212. local_borg_version='1.2.3',
  213. recreate_arguments=flexmock(
  214. list=None,
  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_with_patterns_from_flag():
  225. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  226. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  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. mock_patterns_file = flexmock(name='patterns_file')
  232. flexmock(module).should_receive('write_patterns_file').and_return(mock_patterns_file)
  233. insert_execute_command_mock(
  234. ('borg', 'recreate', '--patterns-from', 'patterns_file', 'repo::archive')
  235. )
  236. module.recreate_archive(
  237. repository='repo',
  238. archive='archive',
  239. config={},
  240. local_borg_version='1.2.3',
  241. recreate_arguments=flexmock(
  242. list=None,
  243. target=None,
  244. comment=None,
  245. timestamp=None,
  246. match_archives=None,
  247. ),
  248. global_arguments=flexmock(dry_run=False, log_json=False),
  249. local_path='borg',
  250. patterns=['pattern1', 'pattern2'],
  251. )
  252. def test_recreate_with_exclude_flags():
  253. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  254. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  255. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  256. flexmock(module.borgmatic.borg.flags).should_receive(
  257. 'make_repository_archive_flags'
  258. ).and_return(('repo::archive',))
  259. flexmock(module).should_receive('make_exclude_flags').and_return(('--exclude', 'pattern'))
  260. insert_execute_command_mock(('borg', 'recreate', '--exclude', 'pattern', 'repo::archive'))
  261. module.recreate_archive(
  262. repository='repo',
  263. archive='archive',
  264. config={'exclude_patterns': ['pattern']},
  265. local_borg_version='1.2.3',
  266. recreate_arguments=flexmock(
  267. list=None,
  268. target=None,
  269. comment=None,
  270. timestamp=None,
  271. match_archives=None,
  272. ),
  273. global_arguments=flexmock(dry_run=False, log_json=False),
  274. local_path='borg',
  275. patterns=None,
  276. )
  277. def test_recreate_with_target_flag():
  278. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  279. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  280. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  281. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  282. flexmock(module.borgmatic.borg.flags).should_receive(
  283. 'make_repository_archive_flags'
  284. ).and_return(('repo::archive',))
  285. insert_execute_command_mock(('borg', 'recreate', '--target', 'new-archive', 'repo::archive'))
  286. module.recreate_archive(
  287. repository='repo',
  288. archive='archive',
  289. config={},
  290. local_borg_version='1.2.3',
  291. recreate_arguments=flexmock(
  292. list=None,
  293. target='new-archive',
  294. comment=None,
  295. timestamp=None,
  296. match_archives=None,
  297. ),
  298. global_arguments=flexmock(dry_run=False, log_json=False),
  299. local_path='borg',
  300. patterns=None,
  301. )
  302. def test_recreate_with_comment_flag():
  303. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  304. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  305. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  306. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  307. flexmock(module.borgmatic.borg.flags).should_receive(
  308. 'make_repository_archive_flags'
  309. ).and_return(('repo::archive',))
  310. insert_execute_command_mock(
  311. ('borg', 'recreate', '--comment', shlex.quote('This is a test comment'), 'repo::archive')
  312. )
  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=None,
  321. comment='This is a test comment',
  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_timestamp_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', '--timestamp', '2023-10-01T12:00:00', '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=None,
  349. timestamp='2023-10-01T12:00:00',
  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_compression_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(('borg', 'recreate', '--compression', 'lz4', 'repo::archive'))
  365. module.recreate_archive(
  366. repository='repo',
  367. archive='archive',
  368. config={'compression': 'lz4'},
  369. local_borg_version='1.2.3',
  370. recreate_arguments=flexmock(
  371. list=None,
  372. target=None,
  373. comment=None,
  374. timestamp=None,
  375. match_archives=None,
  376. ),
  377. global_arguments=flexmock(dry_run=False, log_json=False),
  378. local_path='borg',
  379. patterns=None,
  380. )
  381. def test_recreate_with_chunker_params_flag():
  382. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  383. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  384. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  385. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  386. flexmock(module.borgmatic.borg.flags).should_receive(
  387. 'make_repository_archive_flags'
  388. ).and_return(('repo::archive',))
  389. insert_execute_command_mock(
  390. ('borg', 'recreate', '--chunker-params', '19,23,21,4095', 'repo::archive')
  391. )
  392. module.recreate_archive(
  393. repository='repo',
  394. archive='archive',
  395. config={'chunker_params': '19,23,21,4095'},
  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_recompress_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(('borg', 'recreate', '--recompress', 'always', 'repo::archive'))
  417. module.recreate_archive(
  418. repository='repo',
  419. archive='archive',
  420. config={'recompress': 'always'},
  421. local_borg_version='1.2.3',
  422. recreate_arguments=flexmock(
  423. list=None,
  424. target=None,
  425. comment=None,
  426. timestamp=None,
  427. match_archives=None,
  428. ),
  429. global_arguments=flexmock(dry_run=False, log_json=False),
  430. local_path='borg',
  431. patterns=None,
  432. )
  433. def test_recreate_with_match_archives_star():
  434. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  435. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  436. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  437. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  438. flexmock(module.borgmatic.borg.flags).should_receive(
  439. 'make_repository_archive_flags'
  440. ).and_return(('repo::archive',))
  441. insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
  442. module.recreate_archive(
  443. repository='repo',
  444. archive='archive',
  445. config={},
  446. local_borg_version='1.2.3',
  447. recreate_arguments=flexmock(
  448. list=None,
  449. target=None,
  450. comment=None,
  451. timestamp=None,
  452. match_archives='*',
  453. ),
  454. global_arguments=flexmock(dry_run=False, log_json=False),
  455. local_path='borg',
  456. patterns=None,
  457. )
  458. def test_recreate_with_match_archives_regex():
  459. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  460. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  461. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  462. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  463. flexmock(module.borgmatic.borg.flags).should_receive(
  464. 'make_repository_archive_flags'
  465. ).and_return(('repo::archive',))
  466. insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
  467. module.recreate_archive(
  468. repository='repo',
  469. archive='archive',
  470. config={},
  471. local_borg_version='1.2.3',
  472. recreate_arguments=flexmock(
  473. list=None,
  474. target=None,
  475. comment=None,
  476. timestamp=None,
  477. match_archives='re:.*',
  478. ),
  479. global_arguments=flexmock(dry_run=False, log_json=False),
  480. local_path='borg',
  481. patterns=None,
  482. )
  483. def test_recreate_with_match_archives_shell():
  484. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  485. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  486. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  487. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
  488. flexmock(module.borgmatic.borg.flags).should_receive(
  489. 'make_repository_archive_flags'
  490. ).and_return(('repo::archive',))
  491. insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
  492. module.recreate_archive(
  493. repository='repo',
  494. archive='archive',
  495. config={},
  496. local_borg_version='1.2.3',
  497. recreate_arguments=flexmock(
  498. list=None,
  499. target=None,
  500. comment=None,
  501. timestamp=None,
  502. match_archives='sh:*',
  503. ),
  504. global_arguments=flexmock(dry_run=False, log_json=False),
  505. local_path='borg',
  506. patterns=None,
  507. )
  508. def test_recreate_with_glob_archives_flag():
  509. flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
  510. flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
  511. flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
  512. flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(
  513. ('--glob-archives', 'foo-*')
  514. )
  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', '--glob-archives', 'foo-*', '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='foo-*',
  530. ),
  531. global_arguments=flexmock(dry_run=False, log_json=False),
  532. local_path='borg',
  533. patterns=None,
  534. )
  535. def test_recreate_with_match_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. ('--match-archives', 'sh:foo-*')
  541. )
  542. flexmock(module.borgmatic.borg.flags).should_receive(
  543. 'make_repository_archive_flags'
  544. ).and_return(('--repo', 'repo', 'archive'))
  545. insert_execute_command_mock(
  546. ('borg', 'recreate', '--match-archives', 'sh:foo-*', '--repo', 'repo', 'archive')
  547. )
  548. module.recreate_archive(
  549. repository='repo',
  550. archive='archive',
  551. config={},
  552. local_borg_version='2.0.0b3',
  553. recreate_arguments=flexmock(
  554. list=None,
  555. target=None,
  556. comment=None,
  557. timestamp=None,
  558. match_archives='sh:foo-*',
  559. ),
  560. global_arguments=flexmock(dry_run=False, log_json=False),
  561. local_path='borg',
  562. patterns=None,
  563. )