test_create.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. import os
  2. from flexmock import flexmock
  3. from borgmatic.borg import create as module
  4. from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
  5. def test_initialize_environment_with_passcommand_should_set_environment():
  6. orig_environ = os.environ
  7. try:
  8. os.environ = {}
  9. module.initialize_environment({'encryption_passcommand': 'command'})
  10. assert os.environ.get('BORG_PASSCOMMAND') == 'command'
  11. finally:
  12. os.environ = orig_environ
  13. def test_initialize_environment_with_passphrase_should_set_environment():
  14. orig_environ = os.environ
  15. try:
  16. os.environ = {}
  17. module.initialize_environment({'encryption_passphrase': 'pass'})
  18. assert os.environ.get('BORG_PASSPHRASE') == 'pass'
  19. finally:
  20. os.environ = orig_environ
  21. def test_initialize_environment_with_ssh_command_should_set_environment():
  22. orig_environ = os.environ
  23. try:
  24. os.environ = {}
  25. module.initialize_environment({'ssh_command': 'ssh -C'})
  26. assert os.environ.get('BORG_RSH') == 'ssh -C'
  27. finally:
  28. os.environ = orig_environ
  29. def test_initialize_environment_without_configuration_should_not_set_environment():
  30. orig_environ = os.environ
  31. try:
  32. os.environ = {}
  33. module.initialize_environment({})
  34. assert os.environ.get('BORG_PASSCOMMAND') == None
  35. assert os.environ.get('BORG_PASSPHRASE') == None
  36. assert os.environ.get('BORG_RSH') == None
  37. finally:
  38. os.environ = orig_environ
  39. def test_expand_directory_with_basic_path_passes_it_through():
  40. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  41. flexmock(module.glob).should_receive('glob').and_return([])
  42. paths = module._expand_directory('foo')
  43. assert paths == ['foo']
  44. def test_expand_directory_with_glob_expands():
  45. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  46. flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
  47. paths = module._expand_directory('foo*')
  48. assert paths == ['foo', 'food']
  49. def test_expand_directories_flattens_expanded_directories():
  50. flexmock(module).should_receive('_expand_directory').with_args('~/foo').and_return(['/root/foo'])
  51. flexmock(module).should_receive('_expand_directory').with_args('bar*').and_return(['bar', 'barf'])
  52. paths = module._expand_directories(('~/foo', 'bar*'))
  53. assert paths == ('/root/foo', 'bar', 'barf')
  54. def test_expand_directories_considers_none_as_no_directories():
  55. paths = module._expand_directories(None)
  56. assert paths == ()
  57. def test_write_pattern_file_does_not_raise():
  58. temporary_file = flexmock(
  59. name='filename',
  60. write=lambda mode: None,
  61. flush=lambda: None,
  62. )
  63. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  64. module._write_pattern_file(['exclude'])
  65. def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
  66. module._write_pattern_file([])
  67. def insert_subprocess_mock(check_call_command, **kwargs):
  68. subprocess = flexmock(module.subprocess)
  69. subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
  70. def test_make_pattern_flags_includes_pattern_filename_when_given():
  71. pattern_flags = module._make_pattern_flags(
  72. location_config={'patterns': ['R /', '- /var']},
  73. pattern_filename='/tmp/patterns',
  74. )
  75. assert pattern_flags == ('--patterns-from', '/tmp/patterns')
  76. def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
  77. pattern_flags = module._make_pattern_flags(
  78. location_config={'patterns_from': ['patterns', 'other']},
  79. )
  80. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
  81. def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
  82. pattern_flags = module._make_pattern_flags(
  83. location_config={'patterns_from': ['patterns']},
  84. pattern_filename='/tmp/patterns',
  85. )
  86. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
  87. def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
  88. pattern_flags = module._make_pattern_flags(
  89. location_config={'patterns_from': None},
  90. )
  91. assert pattern_flags == ()
  92. def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
  93. exclude_flags = module._make_exclude_flags(
  94. location_config={'exclude_patterns': ['*.pyc', '/var']},
  95. exclude_filename='/tmp/excludes',
  96. )
  97. assert exclude_flags == ('--exclude-from', '/tmp/excludes')
  98. def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
  99. exclude_flags = module._make_exclude_flags(
  100. location_config={'exclude_from': ['excludes', 'other']},
  101. )
  102. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
  103. def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
  104. exclude_flags = module._make_exclude_flags(
  105. location_config={'exclude_from': ['excludes']},
  106. exclude_filename='/tmp/excludes',
  107. )
  108. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
  109. def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
  110. exclude_flags = module._make_exclude_flags(
  111. location_config={'exclude_from': None},
  112. )
  113. assert exclude_flags == ()
  114. def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
  115. exclude_flags = module._make_exclude_flags(
  116. location_config={'exclude_caches': True},
  117. )
  118. assert exclude_flags == ('--exclude-caches',)
  119. def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
  120. exclude_flags = module._make_exclude_flags(
  121. location_config={'exclude_caches': False},
  122. )
  123. assert exclude_flags == ()
  124. def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
  125. exclude_flags = module._make_exclude_flags(
  126. location_config={'exclude_if_present': 'exclude_me'},
  127. )
  128. assert exclude_flags == ('--exclude-if-present', 'exclude_me')
  129. def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
  130. exclude_flags = module._make_exclude_flags(location_config={})
  131. assert exclude_flags == ()
  132. DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
  133. CREATE_COMMAND = ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
  134. def test_create_archive_calls_borg_with_parameters():
  135. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  136. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  137. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  138. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  139. insert_subprocess_mock(CREATE_COMMAND)
  140. module.create_archive(
  141. verbosity=None,
  142. dry_run=False,
  143. repository='repo',
  144. location_config={
  145. 'source_directories': ['foo', 'bar'],
  146. 'repositories': ['repo'],
  147. 'exclude_patterns': None,
  148. },
  149. storage_config={},
  150. )
  151. def test_create_archive_with_patterns_calls_borg_with_patterns():
  152. pattern_flags = ('--patterns-from', 'patterns')
  153. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  154. flexmock(module).should_receive('_write_pattern_file').and_return(flexmock(name='/tmp/patterns')).and_return(None)
  155. flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
  156. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  157. insert_subprocess_mock(CREATE_COMMAND + pattern_flags)
  158. module.create_archive(
  159. verbosity=None,
  160. dry_run=False,
  161. repository='repo',
  162. location_config={
  163. 'source_directories': ['foo', 'bar'],
  164. 'repositories': ['repo'],
  165. 'patterns': ['pattern'],
  166. },
  167. storage_config={},
  168. )
  169. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  170. exclude_flags = ('--exclude-from', 'excludes')
  171. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(('exclude',))
  172. flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(flexmock(name='/tmp/excludes'))
  173. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  174. flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
  175. insert_subprocess_mock(CREATE_COMMAND + exclude_flags)
  176. module.create_archive(
  177. verbosity=None,
  178. dry_run=False,
  179. repository='repo',
  180. location_config={
  181. 'source_directories': ['foo', 'bar'],
  182. 'repositories': ['repo'],
  183. 'exclude_patterns': ['exclude'],
  184. },
  185. storage_config={},
  186. )
  187. def test_create_archive_with_verbosity_some_calls_borg_with_info_parameter():
  188. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  189. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  190. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  191. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  192. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  193. insert_subprocess_mock(CREATE_COMMAND + ('--info', '--stats',))
  194. module.create_archive(
  195. verbosity=VERBOSITY_SOME,
  196. dry_run=False,
  197. repository='repo',
  198. location_config={
  199. 'source_directories': ['foo', 'bar'],
  200. 'repositories': ['repo'],
  201. 'exclude_patterns': None,
  202. },
  203. storage_config={},
  204. )
  205. def test_create_archive_with_verbosity_lots_calls_borg_with_debug_parameter():
  206. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  207. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  208. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  209. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  210. insert_subprocess_mock(CREATE_COMMAND + ('--debug', '--list', '--stats'))
  211. module.create_archive(
  212. verbosity=VERBOSITY_LOTS,
  213. dry_run=False,
  214. repository='repo',
  215. location_config={
  216. 'source_directories': ['foo', 'bar'],
  217. 'repositories': ['repo'],
  218. 'exclude_patterns': None,
  219. },
  220. storage_config={},
  221. )
  222. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  223. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  224. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  225. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  226. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  227. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  228. insert_subprocess_mock(CREATE_COMMAND + ('--dry-run',))
  229. module.create_archive(
  230. verbosity=None,
  231. dry_run=True,
  232. repository='repo',
  233. location_config={
  234. 'source_directories': ['foo', 'bar'],
  235. 'repositories': ['repo'],
  236. 'exclude_patterns': None,
  237. },
  238. storage_config={},
  239. )
  240. def test_create_archive_with_dry_run_and_verbosity_some_calls_borg_without_stats_parameter():
  241. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  242. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  243. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  244. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  245. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  246. insert_subprocess_mock(CREATE_COMMAND + ('--info', '--dry-run'))
  247. module.create_archive(
  248. verbosity=VERBOSITY_SOME,
  249. dry_run=True,
  250. repository='repo',
  251. location_config={
  252. 'source_directories': ['foo', 'bar'],
  253. 'repositories': ['repo'],
  254. 'exclude_patterns': None,
  255. },
  256. storage_config={},
  257. )
  258. def test_create_archive_with_dry_run_and_verbosity_lots_calls_borg_without_stats_parameter():
  259. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  260. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  261. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  262. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  263. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  264. insert_subprocess_mock(CREATE_COMMAND + ('--debug', '--list', '--dry-run'))
  265. module.create_archive(
  266. verbosity=VERBOSITY_LOTS,
  267. dry_run=True,
  268. repository='repo',
  269. location_config={
  270. 'source_directories': ['foo', 'bar'],
  271. 'repositories': ['repo'],
  272. 'exclude_patterns': None,
  273. },
  274. storage_config={},
  275. )
  276. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  277. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  278. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  279. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  280. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  281. insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle'))
  282. module.create_archive(
  283. verbosity=None,
  284. dry_run=False,
  285. repository='repo',
  286. location_config={
  287. 'source_directories': ['foo', 'bar'],
  288. 'repositories': ['repo'],
  289. 'exclude_patterns': None,
  290. },
  291. storage_config={'compression': 'rle'},
  292. )
  293. def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
  294. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  295. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  296. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  297. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  298. insert_subprocess_mock(CREATE_COMMAND + ('--remote-ratelimit', '100'))
  299. module.create_archive(
  300. verbosity=None,
  301. dry_run=False,
  302. repository='repo',
  303. location_config={
  304. 'source_directories': ['foo', 'bar'],
  305. 'repositories': ['repo'],
  306. 'exclude_patterns': None,
  307. },
  308. storage_config={'remote_rate_limit': 100},
  309. )
  310. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameters():
  311. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  312. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  313. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  314. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  315. insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',))
  316. module.create_archive(
  317. verbosity=None,
  318. dry_run=False,
  319. repository='repo',
  320. location_config={
  321. 'source_directories': ['foo', 'bar'],
  322. 'repositories': ['repo'],
  323. 'one_file_system': True,
  324. 'exclude_patterns': None,
  325. },
  326. storage_config={},
  327. )
  328. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  329. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  330. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  331. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  332. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  333. insert_subprocess_mock(CREATE_COMMAND + ('--files-cache', 'ctime,size'))
  334. module.create_archive(
  335. verbosity=None,
  336. dry_run=False,
  337. repository='repo',
  338. location_config={
  339. 'source_directories': ['foo', 'bar'],
  340. 'repositories': ['repo'],
  341. 'files_cache': 'ctime,size',
  342. 'exclude_patterns': None,
  343. },
  344. storage_config={},
  345. )
  346. def test_create_archive_with_local_path_calls_borg_via_local_path():
  347. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  348. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  349. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  350. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  351. insert_subprocess_mock(('borg1',) + CREATE_COMMAND[1:])
  352. module.create_archive(
  353. verbosity=None,
  354. dry_run=False,
  355. repository='repo',
  356. location_config={
  357. 'source_directories': ['foo', 'bar'],
  358. 'repositories': ['repo'],
  359. 'exclude_patterns': None,
  360. },
  361. storage_config={},
  362. local_path='borg1',
  363. )
  364. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  365. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  366. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  367. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  368. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  369. insert_subprocess_mock(CREATE_COMMAND + ('--remote-path', 'borg1'))
  370. module.create_archive(
  371. verbosity=None,
  372. dry_run=False,
  373. repository='repo',
  374. location_config={
  375. 'source_directories': ['foo', 'bar'],
  376. 'repositories': ['repo'],
  377. 'exclude_patterns': None,
  378. },
  379. storage_config={},
  380. remote_path='borg1',
  381. )
  382. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  383. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  384. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  385. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  386. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  387. insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740'))
  388. module.create_archive(
  389. verbosity=None,
  390. dry_run=False,
  391. repository='repo',
  392. location_config={
  393. 'source_directories': ['foo', 'bar'],
  394. 'repositories': ['repo'],
  395. 'exclude_patterns': None,
  396. },
  397. storage_config={'umask': 740},
  398. )
  399. def test_create_archive_with_source_directories_glob_expands():
  400. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food')).and_return(())
  401. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  402. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  403. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  404. insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'))
  405. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  406. module.create_archive(
  407. verbosity=None,
  408. dry_run=False,
  409. repository='repo',
  410. location_config={
  411. 'source_directories': ['foo*'],
  412. 'repositories': ['repo'],
  413. 'exclude_patterns': None,
  414. },
  415. storage_config={},
  416. )
  417. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  418. flexmock(module).should_receive('_expand_directories').and_return(('foo*',)).and_return(())
  419. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  420. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  421. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  422. insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'))
  423. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  424. module.create_archive(
  425. verbosity=None,
  426. dry_run=False,
  427. repository='repo',
  428. location_config={
  429. 'source_directories': ['foo*'],
  430. 'repositories': ['repo'],
  431. 'exclude_patterns': None,
  432. },
  433. storage_config={},
  434. )
  435. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  436. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food')).and_return(())
  437. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  438. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  439. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  440. insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'))
  441. module.create_archive(
  442. verbosity=None,
  443. dry_run=False,
  444. repository='repo',
  445. location_config={
  446. 'source_directories': ['foo*'],
  447. 'repositories': ['repo'],
  448. 'exclude_patterns': None,
  449. },
  450. storage_config={},
  451. )
  452. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  453. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
  454. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  455. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  456. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  457. insert_subprocess_mock(('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'))
  458. module.create_archive(
  459. verbosity=None,
  460. dry_run=False,
  461. repository='repo',
  462. location_config={
  463. 'source_directories': ['foo', 'bar'],
  464. 'repositories': ['repo'],
  465. 'exclude_patterns': None,
  466. },
  467. storage_config={
  468. 'archive_name_format': 'ARCHIVE_NAME',
  469. },
  470. )
  471. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  472. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return([])
  473. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  474. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  475. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  476. insert_subprocess_mock(('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'))
  477. module.create_archive(
  478. verbosity=None,
  479. dry_run=False,
  480. repository='repo',
  481. location_config={
  482. 'source_directories': ['foo', 'bar'],
  483. 'repositories': ['repo'],
  484. 'exclude_patterns': None,
  485. },
  486. storage_config={
  487. 'archive_name_format': 'Documents_{hostname}-{now}',
  488. },
  489. )