test_create.py 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.borg import create as module
  5. from ..test_verbosity import insert_logging_mock
  6. def test_expand_directory_with_basic_path_passes_it_through():
  7. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  8. flexmock(module.glob).should_receive('glob').and_return([])
  9. paths = module._expand_directory('foo')
  10. assert paths == ['foo']
  11. def test_expand_directory_with_glob_expands():
  12. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  13. flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
  14. paths = module._expand_directory('foo*')
  15. assert paths == ['foo', 'food']
  16. def test_expand_directories_flattens_expanded_directories():
  17. flexmock(module).should_receive('_expand_directory').with_args('~/foo').and_return(
  18. ['/root/foo']
  19. )
  20. flexmock(module).should_receive('_expand_directory').with_args('bar*').and_return(
  21. ['bar', 'barf']
  22. )
  23. paths = module._expand_directories(('~/foo', 'bar*'))
  24. assert paths == ('/root/foo', 'bar', 'barf')
  25. def test_expand_directories_considers_none_as_no_directories():
  26. paths = module._expand_directories(None)
  27. assert paths == ()
  28. def test_expand_home_directories_expands_tildes():
  29. flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
  30. flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
  31. paths = module._expand_home_directories(('~/bar', 'baz'))
  32. assert paths == ('/foo/bar', 'baz')
  33. def test_expand_home_directories_considers_none_as_no_directories():
  34. paths = module._expand_home_directories(None)
  35. assert paths == ()
  36. def test_write_pattern_file_does_not_raise():
  37. temporary_file = flexmock(name='filename', write=lambda mode: None, flush=lambda: None)
  38. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  39. module._write_pattern_file(['exclude'])
  40. def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
  41. module._write_pattern_file([])
  42. def test_make_pattern_flags_includes_pattern_filename_when_given():
  43. pattern_flags = module._make_pattern_flags(
  44. location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
  45. )
  46. assert pattern_flags == ('--patterns-from', '/tmp/patterns')
  47. def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
  48. pattern_flags = module._make_pattern_flags(
  49. location_config={'patterns_from': ['patterns', 'other']}
  50. )
  51. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
  52. def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
  53. pattern_flags = module._make_pattern_flags(
  54. location_config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
  55. )
  56. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
  57. def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
  58. pattern_flags = module._make_pattern_flags(location_config={'patterns_from': None})
  59. assert pattern_flags == ()
  60. def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
  61. exclude_flags = module._make_exclude_flags(
  62. location_config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
  63. )
  64. assert exclude_flags == ('--exclude-from', '/tmp/excludes')
  65. def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
  66. exclude_flags = module._make_exclude_flags(
  67. location_config={'exclude_from': ['excludes', 'other']}
  68. )
  69. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
  70. def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
  71. exclude_flags = module._make_exclude_flags(
  72. location_config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
  73. )
  74. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
  75. def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
  76. exclude_flags = module._make_exclude_flags(location_config={'exclude_from': None})
  77. assert exclude_flags == ()
  78. def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
  79. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': True})
  80. assert exclude_flags == ('--exclude-caches',)
  81. def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
  82. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': False})
  83. assert exclude_flags == ()
  84. def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
  85. exclude_flags = module._make_exclude_flags(location_config={'exclude_if_present': 'exclude_me'})
  86. assert exclude_flags == ('--exclude-if-present', 'exclude_me')
  87. def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
  88. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': True})
  89. assert exclude_flags == ('--keep-exclude-tags',)
  90. def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
  91. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': False})
  92. assert exclude_flags == ()
  93. def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
  94. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': True})
  95. assert exclude_flags == ('--exclude-nodump',)
  96. def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
  97. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': False})
  98. assert exclude_flags == ()
  99. def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
  100. exclude_flags = module._make_exclude_flags(location_config={})
  101. assert exclude_flags == ()
  102. def test_borgmatic_source_directories_set_when_directory_exists():
  103. flexmock(module.os.path).should_receive('exists').and_return(True)
  104. flexmock(module.os.path).should_receive('expanduser')
  105. assert module.borgmatic_source_directories('/tmp') == ['/tmp']
  106. def test_borgmatic_source_directories_empty_when_directory_does_not_exist():
  107. flexmock(module.os.path).should_receive('exists').and_return(False)
  108. flexmock(module.os.path).should_receive('expanduser')
  109. assert module.borgmatic_source_directories('/tmp') == []
  110. def test_borgmatic_source_directories_defaults_when_directory_not_given():
  111. flexmock(module.os.path).should_receive('exists').and_return(True)
  112. flexmock(module.os.path).should_receive('expanduser')
  113. assert module.borgmatic_source_directories(None) == [module.DEFAULT_BORGMATIC_SOURCE_DIRECTORY]
  114. DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
  115. ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
  116. def test_create_archive_calls_borg_with_parameters():
  117. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  118. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  119. flexmock(module).should_receive('_expand_home_directories').and_return(())
  120. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  121. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  122. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  123. flexmock(module).should_receive('execute_command').with_args(
  124. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  125. output_log_level=logging.INFO,
  126. error_on_warnings=False,
  127. )
  128. module.create_archive(
  129. dry_run=False,
  130. repository='repo',
  131. location_config={
  132. 'source_directories': ['foo', 'bar'],
  133. 'repositories': ['repo'],
  134. 'exclude_patterns': None,
  135. },
  136. storage_config={},
  137. )
  138. def test_create_archive_with_patterns_calls_borg_with_patterns():
  139. pattern_flags = ('--patterns-from', 'patterns')
  140. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  141. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  142. flexmock(module).should_receive('_expand_home_directories').and_return(())
  143. flexmock(module).should_receive('_write_pattern_file').and_return(
  144. flexmock(name='/tmp/patterns')
  145. ).and_return(None)
  146. flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
  147. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  148. flexmock(module).should_receive('execute_command').with_args(
  149. ('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS,
  150. output_log_level=logging.INFO,
  151. error_on_warnings=False,
  152. )
  153. module.create_archive(
  154. dry_run=False,
  155. repository='repo',
  156. location_config={
  157. 'source_directories': ['foo', 'bar'],
  158. 'repositories': ['repo'],
  159. 'patterns': ['pattern'],
  160. },
  161. storage_config={},
  162. )
  163. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  164. exclude_flags = ('--exclude-from', 'excludes')
  165. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  166. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  167. flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
  168. flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
  169. flexmock(name='/tmp/excludes')
  170. )
  171. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  172. flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
  173. flexmock(module).should_receive('execute_command').with_args(
  174. ('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS,
  175. output_log_level=logging.INFO,
  176. error_on_warnings=False,
  177. )
  178. module.create_archive(
  179. dry_run=False,
  180. repository='repo',
  181. location_config={
  182. 'source_directories': ['foo', 'bar'],
  183. 'repositories': ['repo'],
  184. 'exclude_patterns': ['exclude'],
  185. },
  186. storage_config={},
  187. )
  188. def test_create_archive_with_log_info_calls_borg_with_info_parameter():
  189. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  190. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  191. flexmock(module).should_receive('_expand_home_directories').and_return(())
  192. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  193. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  194. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  195. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  196. flexmock(module).should_receive('execute_command').with_args(
  197. ('borg', 'create', '--info') + ARCHIVE_WITH_PATHS,
  198. output_log_level=logging.INFO,
  199. error_on_warnings=False,
  200. )
  201. insert_logging_mock(logging.INFO)
  202. module.create_archive(
  203. dry_run=False,
  204. repository='repo',
  205. location_config={
  206. 'source_directories': ['foo', 'bar'],
  207. 'repositories': ['repo'],
  208. 'exclude_patterns': None,
  209. },
  210. storage_config={},
  211. )
  212. def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
  213. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  214. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  215. flexmock(module).should_receive('_expand_home_directories').and_return(())
  216. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  217. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  218. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  219. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  220. flexmock(module).should_receive('execute_command').with_args(
  221. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  222. output_log_level=None,
  223. error_on_warnings=False,
  224. )
  225. insert_logging_mock(logging.INFO)
  226. module.create_archive(
  227. dry_run=False,
  228. repository='repo',
  229. location_config={
  230. 'source_directories': ['foo', 'bar'],
  231. 'repositories': ['repo'],
  232. 'exclude_patterns': None,
  233. },
  234. storage_config={},
  235. json=True,
  236. )
  237. def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
  238. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  239. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  240. flexmock(module).should_receive('_expand_home_directories').and_return(())
  241. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  242. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  243. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  244. flexmock(module).should_receive('execute_command').with_args(
  245. ('borg', 'create', '--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc')
  246. + ARCHIVE_WITH_PATHS,
  247. output_log_level=logging.INFO,
  248. error_on_warnings=False,
  249. )
  250. insert_logging_mock(logging.DEBUG)
  251. module.create_archive(
  252. dry_run=False,
  253. repository='repo',
  254. location_config={
  255. 'source_directories': ['foo', 'bar'],
  256. 'repositories': ['repo'],
  257. 'exclude_patterns': None,
  258. },
  259. storage_config={},
  260. )
  261. def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
  262. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  263. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  264. flexmock(module).should_receive('_expand_home_directories').and_return(())
  265. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  266. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  267. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  268. flexmock(module).should_receive('execute_command').with_args(
  269. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  270. output_log_level=None,
  271. error_on_warnings=False,
  272. )
  273. insert_logging_mock(logging.DEBUG)
  274. module.create_archive(
  275. dry_run=False,
  276. repository='repo',
  277. location_config={
  278. 'source_directories': ['foo', 'bar'],
  279. 'repositories': ['repo'],
  280. 'exclude_patterns': None,
  281. },
  282. storage_config={},
  283. json=True,
  284. )
  285. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  286. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  287. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  288. flexmock(module).should_receive('_expand_home_directories').and_return(())
  289. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  290. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  291. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  292. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  293. flexmock(module).should_receive('execute_command').with_args(
  294. ('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS,
  295. output_log_level=logging.INFO,
  296. error_on_warnings=False,
  297. )
  298. module.create_archive(
  299. dry_run=True,
  300. repository='repo',
  301. location_config={
  302. 'source_directories': ['foo', 'bar'],
  303. 'repositories': ['repo'],
  304. 'exclude_patterns': None,
  305. },
  306. storage_config={},
  307. )
  308. def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_parameter():
  309. # --dry-run and --stats are mutually exclusive, see:
  310. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  311. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  312. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  313. flexmock(module).should_receive('_expand_home_directories').and_return(())
  314. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  315. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  316. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  317. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  318. flexmock(module).should_receive('execute_command').with_args(
  319. ('borg', 'create', '--info', '--dry-run') + ARCHIVE_WITH_PATHS,
  320. output_log_level=logging.INFO,
  321. error_on_warnings=False,
  322. )
  323. insert_logging_mock(logging.INFO)
  324. module.create_archive(
  325. dry_run=True,
  326. repository='repo',
  327. location_config={
  328. 'source_directories': ['foo', 'bar'],
  329. 'repositories': ['repo'],
  330. 'exclude_patterns': None,
  331. },
  332. storage_config={},
  333. )
  334. def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_parameter():
  335. # --dry-run and --stats are mutually exclusive, see:
  336. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  337. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  338. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  339. flexmock(module).should_receive('_expand_home_directories').and_return(())
  340. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  341. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  342. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  343. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  344. flexmock(module).should_receive('execute_command').with_args(
  345. ('borg', 'create', '--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run')
  346. + ARCHIVE_WITH_PATHS,
  347. output_log_level=logging.INFO,
  348. error_on_warnings=False,
  349. )
  350. insert_logging_mock(logging.DEBUG)
  351. module.create_archive(
  352. dry_run=True,
  353. repository='repo',
  354. location_config={
  355. 'source_directories': ['foo', 'bar'],
  356. 'repositories': ['repo'],
  357. 'exclude_patterns': None,
  358. },
  359. storage_config={},
  360. )
  361. def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
  362. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  363. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  364. flexmock(module).should_receive('_expand_home_directories').and_return(())
  365. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  366. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  367. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  368. flexmock(module).should_receive('execute_command').with_args(
  369. ('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
  370. output_log_level=logging.INFO,
  371. error_on_warnings=False,
  372. )
  373. module.create_archive(
  374. dry_run=False,
  375. repository='repo',
  376. location_config={
  377. 'source_directories': ['foo', 'bar'],
  378. 'repositories': ['repo'],
  379. 'exclude_patterns': None,
  380. },
  381. storage_config={'checkpoint_interval': 600},
  382. )
  383. def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
  384. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  385. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  386. flexmock(module).should_receive('_expand_home_directories').and_return(())
  387. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  388. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  389. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  390. flexmock(module).should_receive('execute_command').with_args(
  391. ('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
  392. output_log_level=logging.INFO,
  393. error_on_warnings=False,
  394. )
  395. module.create_archive(
  396. dry_run=False,
  397. repository='repo',
  398. location_config={
  399. 'source_directories': ['foo', 'bar'],
  400. 'repositories': ['repo'],
  401. 'exclude_patterns': None,
  402. },
  403. storage_config={'chunker_params': '1,2,3,4'},
  404. )
  405. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  406. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  407. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  408. flexmock(module).should_receive('_expand_home_directories').and_return(())
  409. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  410. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  411. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  412. flexmock(module).should_receive('execute_command').with_args(
  413. ('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
  414. output_log_level=logging.INFO,
  415. error_on_warnings=False,
  416. )
  417. module.create_archive(
  418. dry_run=False,
  419. repository='repo',
  420. location_config={
  421. 'source_directories': ['foo', 'bar'],
  422. 'repositories': ['repo'],
  423. 'exclude_patterns': None,
  424. },
  425. storage_config={'compression': 'rle'},
  426. )
  427. def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
  428. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  429. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  430. flexmock(module).should_receive('_expand_home_directories').and_return(())
  431. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  432. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  433. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  434. flexmock(module).should_receive('execute_command').with_args(
  435. ('borg', 'create', '--remote-ratelimit', '100') + ARCHIVE_WITH_PATHS,
  436. output_log_level=logging.INFO,
  437. error_on_warnings=False,
  438. )
  439. module.create_archive(
  440. dry_run=False,
  441. repository='repo',
  442. location_config={
  443. 'source_directories': ['foo', 'bar'],
  444. 'repositories': ['repo'],
  445. 'exclude_patterns': None,
  446. },
  447. storage_config={'remote_rate_limit': 100},
  448. )
  449. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
  450. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  451. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  452. flexmock(module).should_receive('_expand_home_directories').and_return(())
  453. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  454. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  455. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  456. flexmock(module).should_receive('execute_command').with_args(
  457. ('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS,
  458. output_log_level=logging.INFO,
  459. error_on_warnings=False,
  460. )
  461. module.create_archive(
  462. dry_run=False,
  463. repository='repo',
  464. location_config={
  465. 'source_directories': ['foo', 'bar'],
  466. 'repositories': ['repo'],
  467. 'one_file_system': True,
  468. 'exclude_patterns': None,
  469. },
  470. storage_config={},
  471. )
  472. def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_parameter():
  473. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  474. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  475. flexmock(module).should_receive('_expand_home_directories').and_return(())
  476. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  477. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  478. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  479. flexmock(module).should_receive('execute_command').with_args(
  480. ('borg', 'create', '--numeric-owner') + ARCHIVE_WITH_PATHS,
  481. output_log_level=logging.INFO,
  482. error_on_warnings=False,
  483. )
  484. module.create_archive(
  485. dry_run=False,
  486. repository='repo',
  487. location_config={
  488. 'source_directories': ['foo', 'bar'],
  489. 'repositories': ['repo'],
  490. 'numeric_owner': True,
  491. 'exclude_patterns': None,
  492. },
  493. storage_config={},
  494. )
  495. def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
  496. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  497. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  498. flexmock(module).should_receive('_expand_home_directories').and_return(())
  499. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  500. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  501. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  502. flexmock(module).should_receive('execute_command').with_args(
  503. ('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS,
  504. output_log_level=logging.INFO,
  505. error_on_warnings=False,
  506. )
  507. module.create_archive(
  508. dry_run=False,
  509. repository='repo',
  510. location_config={
  511. 'source_directories': ['foo', 'bar'],
  512. 'repositories': ['repo'],
  513. 'read_special': True,
  514. 'exclude_patterns': None,
  515. },
  516. storage_config={},
  517. )
  518. @pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
  519. def test_create_archive_with_option_true_calls_borg_without_corresponding_parameter(option_name):
  520. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  521. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  522. flexmock(module).should_receive('_expand_home_directories').and_return(())
  523. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  524. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  525. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  526. flexmock(module).should_receive('execute_command').with_args(
  527. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  528. output_log_level=logging.INFO,
  529. error_on_warnings=False,
  530. )
  531. module.create_archive(
  532. dry_run=False,
  533. repository='repo',
  534. location_config={
  535. 'source_directories': ['foo', 'bar'],
  536. 'repositories': ['repo'],
  537. option_name: True,
  538. 'exclude_patterns': None,
  539. },
  540. storage_config={},
  541. )
  542. @pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
  543. def test_create_archive_with_option_false_calls_borg_with_corresponding_parameter(option_name):
  544. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  545. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  546. flexmock(module).should_receive('_expand_home_directories').and_return(())
  547. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  548. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  549. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  550. flexmock(module).should_receive('execute_command').with_args(
  551. ('borg', 'create', '--no' + option_name.replace('_', '')) + ARCHIVE_WITH_PATHS,
  552. output_log_level=logging.INFO,
  553. error_on_warnings=False,
  554. )
  555. module.create_archive(
  556. dry_run=False,
  557. repository='repo',
  558. location_config={
  559. 'source_directories': ['foo', 'bar'],
  560. 'repositories': ['repo'],
  561. option_name: False,
  562. 'exclude_patterns': None,
  563. },
  564. storage_config={},
  565. )
  566. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  567. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  568. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  569. flexmock(module).should_receive('_expand_home_directories').and_return(())
  570. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  571. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  572. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  573. flexmock(module).should_receive('execute_command').with_args(
  574. ('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
  575. output_log_level=logging.INFO,
  576. error_on_warnings=False,
  577. )
  578. module.create_archive(
  579. dry_run=False,
  580. repository='repo',
  581. location_config={
  582. 'source_directories': ['foo', 'bar'],
  583. 'repositories': ['repo'],
  584. 'files_cache': 'ctime,size',
  585. 'exclude_patterns': None,
  586. },
  587. storage_config={},
  588. )
  589. def test_create_archive_with_local_path_calls_borg_via_local_path():
  590. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  591. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  592. flexmock(module).should_receive('_expand_home_directories').and_return(())
  593. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  594. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  595. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  596. flexmock(module).should_receive('execute_command').with_args(
  597. ('borg1', 'create') + ARCHIVE_WITH_PATHS,
  598. output_log_level=logging.INFO,
  599. error_on_warnings=False,
  600. )
  601. module.create_archive(
  602. dry_run=False,
  603. repository='repo',
  604. location_config={
  605. 'source_directories': ['foo', 'bar'],
  606. 'repositories': ['repo'],
  607. 'exclude_patterns': None,
  608. },
  609. storage_config={},
  610. local_path='borg1',
  611. )
  612. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  613. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  614. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  615. flexmock(module).should_receive('_expand_home_directories').and_return(())
  616. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  617. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  618. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  619. flexmock(module).should_receive('execute_command').with_args(
  620. ('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
  621. output_log_level=logging.INFO,
  622. error_on_warnings=False,
  623. )
  624. module.create_archive(
  625. dry_run=False,
  626. repository='repo',
  627. location_config={
  628. 'source_directories': ['foo', 'bar'],
  629. 'repositories': ['repo'],
  630. 'exclude_patterns': None,
  631. },
  632. storage_config={},
  633. remote_path='borg1',
  634. )
  635. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  636. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  637. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  638. flexmock(module).should_receive('_expand_home_directories').and_return(())
  639. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  640. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  641. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  642. flexmock(module).should_receive('execute_command').with_args(
  643. ('borg', 'create', '--umask', '740') + ARCHIVE_WITH_PATHS,
  644. output_log_level=logging.INFO,
  645. error_on_warnings=False,
  646. )
  647. module.create_archive(
  648. dry_run=False,
  649. repository='repo',
  650. location_config={
  651. 'source_directories': ['foo', 'bar'],
  652. 'repositories': ['repo'],
  653. 'exclude_patterns': None,
  654. },
  655. storage_config={'umask': 740},
  656. )
  657. def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
  658. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  659. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  660. flexmock(module).should_receive('_expand_home_directories').and_return(())
  661. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  662. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  663. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  664. flexmock(module).should_receive('execute_command').with_args(
  665. ('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS,
  666. output_log_level=logging.INFO,
  667. error_on_warnings=False,
  668. )
  669. module.create_archive(
  670. dry_run=False,
  671. repository='repo',
  672. location_config={
  673. 'source_directories': ['foo', 'bar'],
  674. 'repositories': ['repo'],
  675. 'exclude_patterns': None,
  676. },
  677. storage_config={'lock_wait': 5},
  678. )
  679. def test_create_archive_with_stats_calls_borg_with_stats_parameter():
  680. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  681. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  682. flexmock(module).should_receive('_expand_home_directories').and_return(())
  683. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  684. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  685. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  686. flexmock(module).should_receive('execute_command').with_args(
  687. ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS,
  688. output_log_level=logging.INFO,
  689. error_on_warnings=False,
  690. )
  691. module.create_archive(
  692. dry_run=False,
  693. repository='repo',
  694. location_config={
  695. 'source_directories': ['foo', 'bar'],
  696. 'repositories': ['repo'],
  697. 'exclude_patterns': None,
  698. },
  699. storage_config={},
  700. stats=True,
  701. )
  702. def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
  703. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  704. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  705. flexmock(module).should_receive('_expand_home_directories').and_return(())
  706. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  707. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  708. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  709. flexmock(module).should_receive('execute_command_without_capture').with_args(
  710. ('borg', 'create', '--info', '--progress') + ARCHIVE_WITH_PATHS, error_on_warnings=False
  711. )
  712. insert_logging_mock(logging.INFO)
  713. module.create_archive(
  714. dry_run=False,
  715. repository='repo',
  716. location_config={
  717. 'source_directories': ['foo', 'bar'],
  718. 'repositories': ['repo'],
  719. 'exclude_patterns': None,
  720. },
  721. storage_config={},
  722. progress=True,
  723. )
  724. def test_create_archive_with_progress_calls_borg_with_progress_parameter():
  725. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  726. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  727. flexmock(module).should_receive('_expand_home_directories').and_return(())
  728. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  729. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  730. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  731. flexmock(module).should_receive('execute_command_without_capture').with_args(
  732. ('borg', 'create', '--progress') + ARCHIVE_WITH_PATHS, error_on_warnings=False
  733. )
  734. module.create_archive(
  735. dry_run=False,
  736. repository='repo',
  737. location_config={
  738. 'source_directories': ['foo', 'bar'],
  739. 'repositories': ['repo'],
  740. 'exclude_patterns': None,
  741. },
  742. storage_config={},
  743. progress=True,
  744. )
  745. def test_create_archive_with_json_calls_borg_with_json_parameter():
  746. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  747. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  748. flexmock(module).should_receive('_expand_home_directories').and_return(())
  749. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  750. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  751. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  752. flexmock(module).should_receive('execute_command').with_args(
  753. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  754. output_log_level=None,
  755. error_on_warnings=False,
  756. ).and_return('[]')
  757. json_output = module.create_archive(
  758. dry_run=False,
  759. repository='repo',
  760. location_config={
  761. 'source_directories': ['foo', 'bar'],
  762. 'repositories': ['repo'],
  763. 'exclude_patterns': None,
  764. },
  765. storage_config={},
  766. json=True,
  767. )
  768. assert json_output == '[]'
  769. def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
  770. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  771. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  772. flexmock(module).should_receive('_expand_home_directories').and_return(())
  773. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  774. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  775. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  776. flexmock(module).should_receive('execute_command').with_args(
  777. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  778. output_log_level=None,
  779. error_on_warnings=False,
  780. ).and_return('[]')
  781. json_output = module.create_archive(
  782. dry_run=False,
  783. repository='repo',
  784. location_config={
  785. 'source_directories': ['foo', 'bar'],
  786. 'repositories': ['repo'],
  787. 'exclude_patterns': None,
  788. },
  789. storage_config={},
  790. json=True,
  791. stats=True,
  792. )
  793. assert json_output == '[]'
  794. def test_create_archive_with_source_directories_glob_expands():
  795. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  796. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
  797. flexmock(module).should_receive('_expand_home_directories').and_return(())
  798. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  799. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  800. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  801. flexmock(module).should_receive('execute_command').with_args(
  802. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  803. output_log_level=logging.INFO,
  804. error_on_warnings=False,
  805. )
  806. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  807. module.create_archive(
  808. dry_run=False,
  809. repository='repo',
  810. location_config={
  811. 'source_directories': ['foo*'],
  812. 'repositories': ['repo'],
  813. 'exclude_patterns': None,
  814. },
  815. storage_config={},
  816. )
  817. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  818. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  819. flexmock(module).should_receive('_expand_directories').and_return(('foo*',))
  820. flexmock(module).should_receive('_expand_home_directories').and_return(())
  821. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  822. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  823. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  824. flexmock(module).should_receive('execute_command').with_args(
  825. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
  826. output_log_level=logging.INFO,
  827. error_on_warnings=False,
  828. )
  829. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  830. module.create_archive(
  831. dry_run=False,
  832. repository='repo',
  833. location_config={
  834. 'source_directories': ['foo*'],
  835. 'repositories': ['repo'],
  836. 'exclude_patterns': None,
  837. },
  838. storage_config={},
  839. )
  840. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  841. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  842. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
  843. flexmock(module).should_receive('_expand_home_directories').and_return(())
  844. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  845. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  846. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  847. flexmock(module).should_receive('execute_command').with_args(
  848. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  849. output_log_level=logging.INFO,
  850. error_on_warnings=False,
  851. )
  852. module.create_archive(
  853. dry_run=False,
  854. repository='repo',
  855. location_config={
  856. 'source_directories': ['foo*'],
  857. 'repositories': ['repo'],
  858. 'exclude_patterns': None,
  859. },
  860. storage_config={},
  861. )
  862. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  863. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  864. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  865. flexmock(module).should_receive('_expand_home_directories').and_return(())
  866. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  867. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  868. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  869. flexmock(module).should_receive('execute_command').with_args(
  870. ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
  871. output_log_level=logging.INFO,
  872. error_on_warnings=False,
  873. )
  874. module.create_archive(
  875. dry_run=False,
  876. repository='repo',
  877. location_config={
  878. 'source_directories': ['foo', 'bar'],
  879. 'repositories': ['repo'],
  880. 'exclude_patterns': None,
  881. },
  882. storage_config={'archive_name_format': 'ARCHIVE_NAME'},
  883. )
  884. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  885. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  886. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  887. flexmock(module).should_receive('_expand_home_directories').and_return(())
  888. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  889. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  890. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  891. flexmock(module).should_receive('execute_command').with_args(
  892. ('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'),
  893. output_log_level=logging.INFO,
  894. error_on_warnings=False,
  895. )
  896. module.create_archive(
  897. dry_run=False,
  898. repository='repo',
  899. location_config={
  900. 'source_directories': ['foo', 'bar'],
  901. 'repositories': ['repo'],
  902. 'exclude_patterns': None,
  903. },
  904. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  905. )
  906. def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
  907. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  908. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  909. flexmock(module).should_receive('_expand_home_directories').and_return(())
  910. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  911. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  912. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  913. flexmock(module).should_receive('execute_command').with_args(
  914. ('borg', 'create', '--extra', '--options') + ARCHIVE_WITH_PATHS,
  915. output_log_level=logging.INFO,
  916. error_on_warnings=False,
  917. )
  918. module.create_archive(
  919. dry_run=False,
  920. repository='repo',
  921. location_config={
  922. 'source_directories': ['foo', 'bar'],
  923. 'repositories': ['repo'],
  924. 'exclude_patterns': None,
  925. },
  926. storage_config={'extra_borg_options': {'create': '--extra --options'}},
  927. )