test_recreate.py 25 KB

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