2018-09-30 08:15:18 +02:00
|
|
|
import logging
|
2022-03-08 00:32:07 +01:00
|
|
|
import sys
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2019-06-25 20:30:55 +02:00
|
|
|
import pytest
|
2017-08-06 01:21:39 +02:00
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.borg import create as module
|
2019-05-13 23:39:10 +02:00
|
|
|
|
2018-09-30 22:57:20 +02:00
|
|
|
from ..test_verbosity import insert_logging_mock
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2017-09-10 02:23:31 +02:00
|
|
|
def test_expand_directory_with_basic_path_passes_it_through():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_return('foo')
|
|
|
|
flexmock(module.glob).should_receive('glob').and_return([])
|
|
|
|
|
2022-03-07 20:58:29 +01:00
|
|
|
paths = module.expand_directory('foo')
|
2017-09-10 02:23:31 +02:00
|
|
|
|
|
|
|
assert paths == ['foo']
|
|
|
|
|
|
|
|
|
|
|
|
def test_expand_directory_with_glob_expands():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
|
|
|
|
flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
|
|
|
|
|
2022-03-07 20:58:29 +01:00
|
|
|
paths = module.expand_directory('foo*')
|
2017-09-10 02:23:31 +02:00
|
|
|
|
|
|
|
assert paths == ['foo', 'food']
|
|
|
|
|
|
|
|
|
2018-02-19 00:34:19 +01:00
|
|
|
def test_expand_directories_flattens_expanded_directories():
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directory').with_args('~/foo').and_return(['/root/foo'])
|
|
|
|
flexmock(module).should_receive('expand_directory').with_args('bar*').and_return(
|
2018-09-30 07:45:00 +02:00
|
|
|
['bar', 'barf']
|
|
|
|
)
|
2018-02-19 00:34:19 +01:00
|
|
|
|
2022-03-07 20:58:29 +01:00
|
|
|
paths = module.expand_directories(('~/foo', 'bar*'))
|
2018-02-19 00:34:19 +01:00
|
|
|
|
|
|
|
assert paths == ('/root/foo', 'bar', 'barf')
|
|
|
|
|
|
|
|
|
|
|
|
def test_expand_directories_considers_none_as_no_directories():
|
2022-03-07 20:58:29 +01:00
|
|
|
paths = module.expand_directories(None)
|
2018-02-19 00:34:19 +01:00
|
|
|
|
|
|
|
assert paths == ()
|
|
|
|
|
|
|
|
|
2019-01-27 22:47:26 +01:00
|
|
|
def test_expand_home_directories_expands_tildes():
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
|
|
|
|
|
2022-03-07 20:58:29 +01:00
|
|
|
paths = module.expand_home_directories(('~/bar', 'baz'))
|
2019-01-27 22:47:26 +01:00
|
|
|
|
|
|
|
assert paths == ('/foo/bar', 'baz')
|
|
|
|
|
|
|
|
|
|
|
|
def test_expand_home_directories_considers_none_as_no_directories():
|
2022-03-07 20:58:29 +01:00
|
|
|
paths = module.expand_home_directories(None)
|
2019-01-27 22:47:26 +01:00
|
|
|
|
|
|
|
assert paths == ()
|
|
|
|
|
|
|
|
|
2021-10-11 19:40:10 +02:00
|
|
|
def test_map_directories_to_devices_gives_device_id_per_path():
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=66))
|
|
|
|
|
|
|
|
device_map = module.map_directories_to_devices(('/foo', '/bar'))
|
|
|
|
|
|
|
|
assert device_map == {
|
|
|
|
'/foo': 55,
|
|
|
|
'/bar': 66,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def test_map_directories_to_devices_with_missing_path_does_not_error():
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
|
|
|
|
flexmock(module.os).should_receive('stat').with_args('/bar').and_raise(FileNotFoundError)
|
|
|
|
|
|
|
|
device_map = module.map_directories_to_devices(('/foo', '/bar'))
|
|
|
|
|
|
|
|
assert device_map == {
|
|
|
|
'/foo': 55,
|
|
|
|
'/bar': None,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-20 22:33:53 +02:00
|
|
|
@pytest.mark.parametrize(
|
2022-09-08 19:16:42 +02:00
|
|
|
'directories,additional_directories,expected_directories',
|
2020-05-20 22:33:53 +02:00
|
|
|
(
|
2022-09-08 19:16:42 +02:00
|
|
|
({'/': 1, '/root': 1}, {}, ('/',)),
|
|
|
|
({'/': 1, '/root/': 1}, {}, ('/',)),
|
|
|
|
({'/': 1, '/root': 2}, {}, ('/', '/root')),
|
|
|
|
({'/root': 1, '/': 1}, {}, ('/',)),
|
|
|
|
({'/root': 1, '/root/foo': 1}, {}, ('/root',)),
|
|
|
|
({'/root/': 1, '/root/foo': 1}, {}, ('/root/',)),
|
|
|
|
({'/root': 1, '/root/foo/': 1}, {}, ('/root',)),
|
|
|
|
({'/root': 1, '/root/foo': 2}, {}, ('/root', '/root/foo')),
|
|
|
|
({'/root/foo': 1, '/root': 1}, {}, ('/root',)),
|
|
|
|
({'/root': None, '/root/foo': None}, {}, ('/root', '/root/foo')),
|
|
|
|
({'/root': 1, '/etc': 1, '/root/foo/bar': 1}, {}, ('/etc', '/root')),
|
|
|
|
({'/root': 1, '/root/foo': 1, '/root/foo/bar': 1}, {}, ('/root',)),
|
|
|
|
({'/dup': 1, '/dup': 1}, {}, ('/dup',)),
|
|
|
|
({'/foo': 1, '/bar': 1}, {}, ('/bar', '/foo')),
|
|
|
|
({'/foo': 1, '/bar': 2}, {}, ('/bar', '/foo')),
|
|
|
|
({'/root/foo': 1}, {'/root': 1}, ()),
|
|
|
|
({'/root/foo': 1}, {'/root': 2}, ('/root/foo',)),
|
|
|
|
({'/root/foo': 1}, {}, ('/root/foo',)),
|
2020-05-20 22:33:53 +02:00
|
|
|
),
|
|
|
|
)
|
2020-06-20 05:16:38 +02:00
|
|
|
def test_deduplicate_directories_removes_child_paths_on_the_same_filesystem(
|
2022-09-08 19:16:42 +02:00
|
|
|
directories, additional_directories, expected_directories
|
2020-06-20 05:16:38 +02:00
|
|
|
):
|
2022-09-08 19:16:42 +02:00
|
|
|
assert (
|
|
|
|
module.deduplicate_directories(directories, additional_directories) == expected_directories
|
|
|
|
)
|
2020-05-20 22:33:53 +02:00
|
|
|
|
|
|
|
|
2022-08-25 20:55:34 +02:00
|
|
|
def test_write_pattern_file_writes_pattern_lines():
|
|
|
|
temporary_file = flexmock(name='filename', flush=lambda: None)
|
|
|
|
temporary_file.should_receive('write').with_args('R /foo\n+ /foo/bar')
|
2017-08-06 01:21:39 +02:00
|
|
|
flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
|
|
|
|
|
2022-08-25 20:55:34 +02:00
|
|
|
module.write_pattern_file(['R /foo', '+ /foo/bar'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_write_pattern_file_with_sources_writes_sources_as_roots():
|
|
|
|
temporary_file = flexmock(name='filename', flush=lambda: None)
|
|
|
|
temporary_file.should_receive('write').with_args('R /foo\n+ /foo/bar\nR /baz\nR /quux')
|
|
|
|
flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
|
|
|
|
|
|
|
|
module.write_pattern_file(['R /foo', '+ /foo/bar'], sources=['/baz', '/quux'])
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2022-10-05 07:57:18 +02:00
|
|
|
def test_write_pattern_file_without_patterns_but_with_sources_writes_sources_as_roots():
|
|
|
|
temporary_file = flexmock(name='filename', flush=lambda: None)
|
|
|
|
temporary_file.should_receive('write').with_args('R /baz\nR /quux')
|
|
|
|
flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
|
|
|
|
|
|
|
|
module.write_pattern_file([], sources=['/baz', '/quux'])
|
|
|
|
|
|
|
|
|
2018-01-15 00:52:19 +01:00
|
|
|
def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
|
2022-03-07 20:58:29 +01:00
|
|
|
module.write_pattern_file([])
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
def test_write_pattern_file_overwrites_existing_file():
|
|
|
|
pattern_file = flexmock(name='filename', flush=lambda: None)
|
|
|
|
pattern_file.should_receive('seek').with_args(0).once()
|
|
|
|
pattern_file.should_receive('write').with_args('R /foo\n+ /foo/bar')
|
|
|
|
flexmock(module.tempfile).should_receive('NamedTemporaryFile').never()
|
|
|
|
|
|
|
|
module.write_pattern_file(['R /foo', '+ /foo/bar'], pattern_file=pattern_file)
|
|
|
|
|
|
|
|
|
2022-03-08 00:32:07 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'filename_lists,opened_filenames',
|
|
|
|
(
|
|
|
|
([('foo', 'bar'), ('baz', 'quux')], ('foo', 'bar', 'baz', 'quux')),
|
|
|
|
([None, ('foo', 'bar')], ('foo', 'bar')),
|
|
|
|
([None, None], ()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
def test_ensure_files_readable_opens_filenames(filename_lists, opened_filenames):
|
|
|
|
for expected_filename in opened_filenames:
|
|
|
|
flexmock(sys.modules['builtins']).should_receive('open').with_args(
|
|
|
|
expected_filename
|
|
|
|
).and_return(flexmock(close=lambda: None))
|
|
|
|
|
|
|
|
module.ensure_files_readable(*filename_lists)
|
|
|
|
|
|
|
|
|
2018-01-15 00:52:19 +01:00
|
|
|
def test_make_pattern_flags_includes_pattern_filename_when_given():
|
2022-03-07 20:58:29 +01:00
|
|
|
pattern_flags = module.make_pattern_flags(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
|
2018-01-15 00:52:19 +01:00
|
|
|
)
|
|
|
|
|
2018-01-16 05:22:53 +01:00
|
|
|
assert pattern_flags == ('--patterns-from', '/tmp/patterns')
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
pattern_flags = module.make_pattern_flags(config={'patterns_from': ['patterns', 'other']})
|
2018-01-15 00:52:19 +01:00
|
|
|
|
2018-01-16 05:22:53 +01:00
|
|
|
assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
|
2022-03-07 20:58:29 +01:00
|
|
|
pattern_flags = module.make_pattern_flags(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
|
2018-01-15 00:52:19 +01:00
|
|
|
)
|
|
|
|
|
2018-01-16 05:22:53 +01:00
|
|
|
assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
|
2023-07-09 08:14:30 +02:00
|
|
|
pattern_flags = module.make_pattern_flags(config={'patterns_from': None})
|
2018-01-15 00:52:19 +01:00
|
|
|
|
|
|
|
assert pattern_flags == ()
|
|
|
|
|
|
|
|
|
2017-08-06 08:32:39 +02:00
|
|
|
def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
|
2022-03-07 20:58:29 +01:00
|
|
|
exclude_flags = module.make_exclude_flags(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
|
2017-08-06 08:32:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-from', '/tmp/excludes')
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'exclude_from': ['excludes', 'other']})
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
|
2022-03-07 20:58:29 +01:00
|
|
|
exclude_flags = module.make_exclude_flags(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
|
2017-08-06 08:32:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
|
|
|
|
|
|
|
|
|
2017-08-27 19:01:49 +02:00
|
|
|
def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'exclude_from': None})
|
2017-08-27 19:01:49 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
2017-08-06 08:32:39 +02:00
|
|
|
def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'exclude_caches': True})
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-caches',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'exclude_caches': False})
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
|
2022-03-07 20:58:29 +01:00
|
|
|
exclude_flags = module.make_exclude_flags(
|
2023-07-09 08:14:30 +02:00
|
|
|
config={'exclude_if_present': ['exclude_me', 'also_me']}
|
2020-01-23 22:41:37 +01:00
|
|
|
)
|
2017-08-06 08:32:39 +02:00
|
|
|
|
2020-01-23 22:41:37 +01:00
|
|
|
assert exclude_flags == (
|
|
|
|
'--exclude-if-present',
|
|
|
|
'exclude_me',
|
|
|
|
'--exclude-if-present',
|
|
|
|
'also_me',
|
|
|
|
)
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
|
2019-11-01 23:50:59 +01:00
|
|
|
def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'keep_exclude_tags': True})
|
2019-11-01 23:50:59 +01:00
|
|
|
|
|
|
|
assert exclude_flags == ('--keep-exclude-tags',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'keep_exclude_tags': False})
|
2019-11-01 23:50:59 +01:00
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'exclude_nodump': True})
|
2019-11-01 23:50:59 +01:00
|
|
|
|
|
|
|
assert exclude_flags == ('--exclude-nodump',)
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={'exclude_nodump': False})
|
2019-11-01 23:50:59 +01:00
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
2017-08-06 08:32:39 +02:00
|
|
|
def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
|
2023-07-09 08:14:30 +02:00
|
|
|
exclude_flags = module.make_exclude_flags(config={})
|
2017-08-06 08:32:39 +02:00
|
|
|
|
|
|
|
assert exclude_flags == ()
|
|
|
|
|
|
|
|
|
2023-03-03 00:33:42 +01:00
|
|
|
def test_make_list_filter_flags_with_debug_and_feature_available_includes_plus_and_minus():
|
|
|
|
flexmock(module.logger).should_receive('isEnabledFor').and_return(True)
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AME+-'
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_list_filter_flags_with_info_and_feature_available_omits_plus_and_minus():
|
|
|
|
flexmock(module.logger).should_receive('isEnabledFor').and_return(False)
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AME'
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_list_filter_flags_with_debug_and_feature_available_and_dry_run_includes_plus_and_minus():
|
|
|
|
flexmock(module.logger).should_receive('isEnabledFor').and_return(True)
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=True) == 'AME+-'
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_list_filter_flags_with_info_and_feature_available_and_dry_run_includes_plus_and_minus():
|
|
|
|
flexmock(module.logger).should_receive('isEnabledFor').and_return(False)
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
|
|
|
|
assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=True) == 'AME+-'
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_list_filter_flags_with_debug_and_feature_not_available_includes_x():
|
|
|
|
flexmock(module.logger).should_receive('isEnabledFor').and_return(True)
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
|
|
|
|
|
|
|
assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AMEx-'
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_list_filter_flags_with_info_and_feature_not_available_omits_x():
|
|
|
|
flexmock(module.logger).should_receive('isEnabledFor').and_return(False)
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(False)
|
|
|
|
|
|
|
|
assert module.make_list_filter_flags(local_borg_version=flexmock(), dry_run=False) == 'AME-'
|
|
|
|
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
def test_collect_borgmatic_source_directories_set_when_directory_exists():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(True)
|
|
|
|
flexmock(module.os.path).should_receive('expanduser')
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
assert module.collect_borgmatic_source_directories('/tmp') == ['/tmp']
|
2019-10-23 01:28:42 +02:00
|
|
|
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
def test_collect_borgmatic_source_directories_empty_when_directory_does_not_exist():
|
2019-10-23 01:28:42 +02:00
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(False)
|
|
|
|
flexmock(module.os.path).should_receive('expanduser')
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
assert module.collect_borgmatic_source_directories('/tmp') == []
|
2019-12-11 01:04:34 +01:00
|
|
|
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
def test_collect_borgmatic_source_directories_defaults_when_directory_not_given():
|
2019-12-11 01:04:34 +01:00
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(True)
|
|
|
|
flexmock(module.os.path).should_receive('expanduser')
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
assert module.collect_borgmatic_source_directories(None) == [
|
2022-05-28 23:42:19 +02:00
|
|
|
module.state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY
|
|
|
|
]
|
2019-10-23 01:28:42 +02:00
|
|
|
|
|
|
|
|
2022-09-08 19:16:42 +02:00
|
|
|
def test_pattern_root_directories_deals_with_none_patterns():
|
|
|
|
assert module.pattern_root_directories(patterns=None) == []
|
|
|
|
|
|
|
|
|
|
|
|
def test_pattern_root_directories_parses_roots_and_ignores_others():
|
|
|
|
assert module.pattern_root_directories(
|
|
|
|
['R /root', '+ /root/foo', '- /root/foo/bar', 'R /baz']
|
|
|
|
) == ['/root', '/baz']
|
|
|
|
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'character_device,block_device,fifo,expected_result',
|
|
|
|
(
|
|
|
|
(False, False, False, False),
|
|
|
|
(True, False, False, True),
|
|
|
|
(False, True, False, True),
|
|
|
|
(True, True, False, True),
|
|
|
|
(False, False, True, True),
|
|
|
|
(False, True, True, True),
|
|
|
|
(True, False, True, True),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
def test_special_file_looks_at_file_type(character_device, block_device, fifo, expected_result):
|
|
|
|
flexmock(module.os).should_receive('stat').and_return(flexmock(st_mode=flexmock()))
|
|
|
|
flexmock(module.stat).should_receive('S_ISCHR').and_return(character_device)
|
|
|
|
flexmock(module.stat).should_receive('S_ISBLK').and_return(block_device)
|
|
|
|
flexmock(module.stat).should_receive('S_ISFIFO').and_return(fifo)
|
|
|
|
|
|
|
|
assert module.special_file('/dev/special') == expected_result
|
|
|
|
|
|
|
|
|
2022-10-14 18:41:08 +02:00
|
|
|
def test_special_file_treats_broken_symlink_as_non_special():
|
|
|
|
flexmock(module.os).should_receive('stat').and_raise(FileNotFoundError)
|
|
|
|
|
|
|
|
assert module.special_file('/broken/symlink') is False
|
|
|
|
|
|
|
|
|
2022-10-03 21:58:13 +02:00
|
|
|
def test_any_parent_directories_treats_parents_as_match():
|
|
|
|
module.any_parent_directories('/foo/bar.txt', ('/foo', '/etc'))
|
|
|
|
|
|
|
|
|
|
|
|
def test_any_parent_directories_treats_grandparents_as_match():
|
|
|
|
module.any_parent_directories('/foo/bar/baz.txt', ('/foo', '/etc'))
|
|
|
|
|
|
|
|
|
|
|
|
def test_any_parent_directories_treats_unrelated_paths_as_non_match():
|
|
|
|
module.any_parent_directories('/foo/bar.txt', ('/usr', '/etc'))
|
|
|
|
|
|
|
|
|
|
|
|
def test_collect_special_file_paths_parses_special_files_from_borg_dry_run_file_list():
|
2022-10-15 01:19:26 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
|
2023-02-27 07:36:13 +01:00
|
|
|
'Processing files ...\n- /foo\n+ /bar\n- /baz'
|
2022-10-03 21:58:13 +02:00
|
|
|
)
|
|
|
|
flexmock(module).should_receive('special_file').and_return(True)
|
|
|
|
flexmock(module).should_receive('any_parent_directories').and_return(False)
|
|
|
|
|
|
|
|
assert module.collect_special_file_paths(
|
|
|
|
('borg', 'create'),
|
2024-01-21 20:34:40 +01:00
|
|
|
config={},
|
2022-10-03 21:58:13 +02:00
|
|
|
local_path=None,
|
|
|
|
working_directory=None,
|
|
|
|
borg_environment=None,
|
|
|
|
skip_directories=flexmock(),
|
|
|
|
) == ('/foo', '/bar', '/baz')
|
|
|
|
|
|
|
|
|
|
|
|
def test_collect_special_file_paths_excludes_requested_directories():
|
2022-10-15 01:19:26 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
|
2023-02-27 07:36:13 +01:00
|
|
|
'+ /foo\n- /bar\n- /baz'
|
2022-10-15 01:19:26 +02:00
|
|
|
)
|
2022-10-03 21:58:13 +02:00
|
|
|
flexmock(module).should_receive('special_file').and_return(True)
|
|
|
|
flexmock(module).should_receive('any_parent_directories').and_return(False).and_return(
|
|
|
|
True
|
|
|
|
).and_return(False)
|
|
|
|
|
|
|
|
assert module.collect_special_file_paths(
|
|
|
|
('borg', 'create'),
|
2024-01-21 20:34:40 +01:00
|
|
|
config={},
|
2022-10-03 21:58:13 +02:00
|
|
|
local_path=None,
|
|
|
|
working_directory=None,
|
|
|
|
borg_environment=None,
|
|
|
|
skip_directories=flexmock(),
|
|
|
|
) == ('/foo', '/baz')
|
|
|
|
|
|
|
|
|
|
|
|
def test_collect_special_file_paths_excludes_non_special_files():
|
2022-10-15 01:19:26 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').and_return(
|
2023-02-27 07:36:13 +01:00
|
|
|
'+ /foo\n+ /bar\n+ /baz'
|
2022-10-15 01:19:26 +02:00
|
|
|
)
|
2022-10-03 21:58:13 +02:00
|
|
|
flexmock(module).should_receive('special_file').and_return(True).and_return(False).and_return(
|
|
|
|
True
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('any_parent_directories').and_return(False)
|
|
|
|
|
|
|
|
assert module.collect_special_file_paths(
|
|
|
|
('borg', 'create'),
|
2024-01-21 20:34:40 +01:00
|
|
|
config={},
|
2022-10-03 21:58:13 +02:00
|
|
|
local_path=None,
|
|
|
|
working_directory=None,
|
|
|
|
borg_environment=None,
|
|
|
|
skip_directories=flexmock(),
|
|
|
|
) == ('/foo', '/baz')
|
|
|
|
|
|
|
|
|
2023-06-28 18:15:11 +02:00
|
|
|
def test_collect_special_file_paths_omits_exclude_no_dump_flag_from_command():
|
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
|
('borg', 'create', '--dry-run', '--list'),
|
|
|
|
capture_stderr=True,
|
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
2023-07-10 20:16:18 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2023-06-28 18:15:11 +02:00
|
|
|
).and_return('Processing files ...\n- /foo\n+ /bar\n- /baz').once()
|
|
|
|
flexmock(module).should_receive('special_file').and_return(True)
|
|
|
|
flexmock(module).should_receive('any_parent_directories').and_return(False)
|
|
|
|
|
|
|
|
module.collect_special_file_paths(
|
|
|
|
('borg', 'create', '--exclude-nodump'),
|
2024-01-21 20:34:40 +01:00
|
|
|
config={},
|
2023-07-10 20:16:18 +02:00
|
|
|
local_path='borg',
|
2023-06-28 18:15:11 +02:00
|
|
|
working_directory=None,
|
|
|
|
borg_environment=None,
|
|
|
|
skip_directories=flexmock(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-24 07:11:14 +01:00
|
|
|
DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' # noqa: FS003
|
2022-08-13 08:54:13 +02:00
|
|
|
REPO_ARCHIVE_WITH_PATHS = (f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo', 'bar')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_make_base_create_produces_borg_command():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_patterns_file_in_borg_command():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
mock_pattern_file = flexmock(name='/tmp/patterns')
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(mock_pattern_file).and_return(
|
|
|
|
None
|
|
|
|
)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2024-04-04 23:23:56 +02:00
|
|
|
pattern_flags = ('--patterns-from', mock_pattern_file.name)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(pattern_flags)
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2018-01-15 00:52:19 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'patterns': ['pattern'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2018-01-15 00:52:19 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create') + pattern_flags
|
|
|
|
assert create_positional_arguments == (f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
assert pattern_file == mock_pattern_file
|
|
|
|
assert not exclude_file
|
2018-01-15 00:52:19 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_sources_and_config_paths_in_borg_command():
|
2023-06-07 20:37:36 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(
|
2024-01-09 22:47:20 +01:00
|
|
|
('foo', 'bar', '/tmp/test.yaml')
|
2023-06-07 20:37:36 +02:00
|
|
|
)
|
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2023-06-09 21:35:34 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
|
|
|
|
flexmock(module).should_receive('expand_directories').with_args(
|
2024-01-09 22:47:20 +01:00
|
|
|
('foo', 'bar', '/tmp/test.yaml')
|
|
|
|
).and_return(('foo', 'bar', '/tmp/test.yaml'))
|
2023-06-09 21:35:34 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
|
2023-06-07 20:37:36 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2023-06-07 20:37:36 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS + ('/tmp/test.yaml',)
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2023-07-31 23:01:20 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_with_store_config_false_omits_config_files():
|
2023-07-31 23:01:20 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2023-07-31 22:31:15 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
|
|
|
flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
|
2023-07-31 23:01:20 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').with_args(('foo', 'bar')).and_return(
|
2023-07-31 22:56:36 +02:00
|
|
|
('foo', 'bar')
|
2023-07-31 23:01:20 +02:00
|
|
|
)
|
2023-07-31 22:31:15 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').with_args([]).and_return(())
|
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'store_config_files': False,
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2023-07-31 22:31:15 +02:00
|
|
|
)
|
2023-06-07 20:37:36 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2023-07-31 23:01:20 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_exclude_patterns_in_borg_command():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(('exclude',))
|
2024-04-04 23:23:56 +02:00
|
|
|
mock_exclude_file = flexmock(name='/tmp/excludes')
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(mock_exclude_file)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
exclude_flags = ('--exclude-from', 'excludes')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(exclude_flags)
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': ['exclude'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create') + exclude_flags
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert exclude_file == mock_exclude_file
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'option_name,option_value,feature_available,option_flags',
|
|
|
|
(
|
|
|
|
('checkpoint_interval', 600, True, ('--checkpoint-interval', '600')),
|
|
|
|
('checkpoint_volume', 1024, True, ('--checkpoint-volume', '1024')),
|
|
|
|
('chunker_params', '1,2,3,4', True, ('--chunker-params', '1,2,3,4')),
|
|
|
|
('compression', 'rle', True, ('--compression', 'rle')),
|
|
|
|
('one_file_system', True, True, ('--one-file-system',)),
|
|
|
|
('upload_rate_limit', 100, True, ('--upload-ratelimit', '100')),
|
|
|
|
('upload_rate_limit', 100, False, ('--remote-ratelimit', '100')),
|
|
|
|
('numeric_ids', True, True, ('--numeric-ids',)),
|
|
|
|
('numeric_ids', True, False, ('--numeric-owner',)),
|
|
|
|
('read_special', True, True, ('--read-special',)),
|
|
|
|
('ctime', True, True, ()),
|
|
|
|
('ctime', False, True, ('--noctime',)),
|
|
|
|
('birthtime', True, True, ()),
|
|
|
|
('birthtime', False, True, ('--nobirthtime',)),
|
|
|
|
('atime', True, True, ('--atime',)),
|
|
|
|
('atime', True, False, ()),
|
|
|
|
('atime', False, True, ()),
|
|
|
|
('atime', False, False, ('--noatime',)),
|
|
|
|
('flags', True, True, ()),
|
|
|
|
('flags', True, False, ()),
|
|
|
|
('flags', False, True, ('--noflags',)),
|
|
|
|
('flags', False, False, ('--nobsdflags',)),
|
|
|
|
('files_cache', 'ctime,size', True, ('--files-cache', 'ctime,size')),
|
|
|
|
('umask', 740, True, ('--umask', '740')),
|
|
|
|
('lock_wait', 5, True, ('--lock-wait', '5')),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
def test_make_base_create_command_includes_configuration_option_as_command_flag(
|
|
|
|
option_name, option_value, feature_available, option_flags
|
|
|
|
):
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(feature_available)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
option_name: option_value,
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2018-05-27 00:09:23 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create') + option_flags
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2018-05-27 00:09:23 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_dry_run_in_borg_command():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2018-05-27 00:09:23 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=True,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': ['exclude'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2018-05-27 00:09:23 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create', '--dry-run')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2018-05-27 00:09:23 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_local_path_in_borg_command():
|
2022-02-10 06:11:00 +01:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2022-02-10 06:11:00 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
local_path='borg1',
|
|
|
|
)
|
2022-02-10 06:11:00 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg1', 'create')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2022-02-10 06:11:00 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_remote_path_in_borg_command():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2017-11-03 06:03:11 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
remote_path='borg1',
|
|
|
|
)
|
2017-11-03 06:03:11 +01:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create', '--remote-path', 'borg1')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_log_json_in_borg_command():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2018-01-15 01:35:24 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=True),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2018-01-15 01:35:24 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create', '--log-json')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2018-01-15 01:35:24 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_list_flags_in_borg_command():
|
2024-01-21 20:34:40 +01:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
list_files=True,
|
|
|
|
)
|
2024-01-21 20:34:40 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create', '--list', '--filter', 'FOO')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2024-01-21 20:34:40 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_with_stream_processes_ignores_read_special_false_and_logs_warning():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module.logger).should_receive('warning').once()
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'read_special': False,
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
stream_processes=flexmock(),
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create', '--one-file-system', '--read-special')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_with_non_matching_source_directories_glob_passes_through():
|
2022-10-03 21:58:13 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo*',))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo*'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2023-05-09 08:00:49 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == (f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo*')
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2023-05-09 08:00:49 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_expands_glob_in_source_directories():
|
2023-05-09 08:00:49 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
|
2023-05-09 08:00:49 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo*'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == (f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo', 'food')
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_archive_name_format_in_borg_command():
|
2022-10-03 21:58:13 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
2024-04-04 23:23:56 +02:00
|
|
|
('repo::ARCHIVE_NAME',)
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2018-02-20 00:51:04 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'archive_name_format': 'ARCHIVE_NAME',
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2018-02-20 00:51:04 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == ('repo::ARCHIVE_NAME', 'foo', 'bar')
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2018-02-20 00:51:04 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_base_create_command_includes_archive_name_format_with_placeholders_in_borg_command():
|
|
|
|
repository_archive_pattern = 'repo::Documents_{hostname}-{now}' # noqa: FS003
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
2024-04-04 23:23:56 +02:00
|
|
|
(repository_archive_pattern,)
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'archive_name_format': 'Documents_{hostname}-{now}', # noqa: FS003
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == (repository_archive_pattern, 'foo', 'bar')
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2020-01-22 22:28:24 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_base_create_command_includes_repository_and_archive_name_format_with_placeholders_in_borg_command():
|
|
|
|
repository_archive_pattern = '{fqdn}::Documents_{hostname}-{now}' # noqa: FS003
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
2024-04-04 23:23:56 +02:00
|
|
|
(repository_archive_pattern,)
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='{fqdn}', # noqa: FS003
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['{fqdn}'], # noqa: FS003
|
|
|
|
'archive_name_format': 'Documents_{hostname}-{now}', # noqa: FS003
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2020-01-22 22:28:24 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create')
|
|
|
|
assert create_positional_arguments == (repository_archive_pattern, 'foo', 'bar')
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2020-01-22 22:28:24 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_includes_extra_borg_options_in_borg_command():
|
2020-05-20 22:33:53 +02:00
|
|
|
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
2020-06-20 05:16:38 +02:00
|
|
|
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2022-09-08 19:16:42 +02:00
|
|
|
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
2022-03-03 20:48:18 +01:00
|
|
|
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
2023-03-03 00:33:42 +01:00
|
|
|
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
2022-02-10 01:54:35 +01:00
|
|
|
flexmock(module.feature).should_receive('available').and_return(True)
|
2022-03-08 00:32:07 +01:00
|
|
|
flexmock(module).should_receive('ensure_files_readable')
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2022-08-14 07:50:14 +02:00
|
|
|
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
|
|
|
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
|
|
|
)
|
2019-12-01 00:31:36 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
(create_flags, create_positional_arguments, pattern_file, exclude_file) = (
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'extra_borg_options': {'create': '--extra --options'},
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
2019-12-01 00:31:36 +01:00
|
|
|
)
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
assert create_flags == ('borg', 'create', '--extra', '--options')
|
|
|
|
assert create_positional_arguments == REPO_ARCHIVE_WITH_PATHS
|
|
|
|
assert not pattern_file
|
|
|
|
assert not exclude_file
|
2019-12-01 00:31:36 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
|
|
|
|
def test_make_base_create_command_with_non_existent_directory_and_source_directories_must_exist_raises():
|
|
|
|
flexmock(module).should_receive('check_all_source_directories_exist').and_raise(ValueError)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.make_base_create_command(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'source_directories_must_exist': True,
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
borgmatic_source_directories=(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_calls_borg_with_parameters():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2020-05-10 06:53:16 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-04-04 23:23:56 +02:00
|
|
|
('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_log_level=logging.INFO,
|
2024-04-04 23:23:56 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2019-09-25 21:03:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2019-09-25 21:03:10 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2019-09-25 21:03:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_calls_borg_with_environment():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-10-03 21:58:13 +02:00
|
|
|
)
|
2024-04-04 23:23:56 +02:00
|
|
|
environment = {'BORG_THINGY': 'YUP'}
|
|
|
|
flexmock(module.environment).should_receive('make_environment').and_return(environment)
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
|
2020-05-11 20:34:14 +02:00
|
|
|
output_log_level=logging.INFO,
|
2024-04-04 23:23:56 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2024-04-04 23:23:56 +02:00
|
|
|
extra_environment=environment,
|
2020-05-11 20:34:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2020-05-11 20:34:14 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2020-05-11 20:34:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-09-20 22:52:13 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-09-20 22:52:13 +02:00
|
|
|
)
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create', '--info') + REPO_ARCHIVE_WITH_PATHS,
|
2022-09-20 22:52:13 +02:00
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=None,
|
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2022-09-20 22:52:13 +02:00
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
)
|
2024-04-04 23:23:56 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2022-09-20 22:52:13 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2022-09-20 22:52:13 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-09-20 22:52:13 +02:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2022-09-20 22:52:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-06 20:07:43 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-10-06 20:07:43 +02:00
|
|
|
)
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
|
('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS,
|
2022-10-06 20:07:43 +02:00
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2022-10-06 20:07:43 +02:00
|
|
|
)
|
2024-04-04 23:23:56 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2022-10-06 20:07:43 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2022-10-06 20:07:43 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-10-06 20:07:43 +02:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-04-04 23:23:56 +02:00
|
|
|
json=True,
|
2022-10-06 20:07:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-10-06 20:07:43 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-10-06 20:07:43 +02:00
|
|
|
)
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create', '--debug', '--show-rc') + REPO_ARCHIVE_WITH_PATHS,
|
2022-10-06 20:07:43 +02:00
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=None,
|
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2022-10-06 20:07:43 +02:00
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
)
|
2024-04-04 23:23:56 +02:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2022-10-06 20:07:43 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2022-10-06 20:07:43 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-10-06 20:07:43 +02:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2022-10-06 20:07:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2022-10-15 01:19:26 +02:00
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
2023-08-05 05:02:09 +02:00
|
|
|
('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2023-07-10 20:16:18 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2024-04-04 23:23:56 +02:00
|
|
|
)
|
|
|
|
insert_logging_mock(logging.DEBUG)
|
2018-09-24 21:52:04 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
module.create_archive(
|
2018-09-24 21:52:04 +02:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2018-09-24 21:52:04 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2018-09-30 07:45:00 +02:00
|
|
|
json=True,
|
2018-09-24 21:52:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats():
|
|
|
|
# --dry-run and --stats are mutually exclusive, see:
|
|
|
|
# https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create', '--dry-run'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create', '--dry-run', '--info') + REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=None,
|
2023-07-10 20:16:18 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2024-04-04 23:23:56 +02:00
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
)
|
|
|
|
insert_logging_mock(logging.INFO)
|
2019-06-12 20:49:35 +02:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
module.create_archive(
|
|
|
|
dry_run=True,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2019-06-12 20:49:35 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2019-06-12 20:49:35 +02:00
|
|
|
stats=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_working_directory_calls_borg_with_working_directory():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-04-04 23:23:56 +02:00
|
|
|
('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2024-04-04 23:23:56 +02:00
|
|
|
working_directory='/working/dir',
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2018-09-30 07:45:00 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2024-04-04 23:23:56 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
2017-08-06 01:21:39 +02:00
|
|
|
'repositories': ['repo'],
|
2024-04-04 23:23:56 +02:00
|
|
|
'working_directory': '/working/dir',
|
2017-08-06 01:21:39 +02:00
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_exit_codes_calls_borg_using_them():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
|
|
|
)
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
borg_exit_codes = flexmock()
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=None,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=borg_exit_codes,
|
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
'borg_exit_codes': borg_exit_codes,
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_answer_output_log_level():
|
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-04-04 23:23:56 +02:00
|
|
|
('borg', 'create', '--stats') + REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=module.borgmatic.logger.ANSWER,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2024-04-04 23:23:56 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
2017-08-06 01:21:39 +02:00
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-04-04 23:23:56 +02:00
|
|
|
stats=True,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_files_calls_borg_with_answer_output_log_level():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(
|
|
|
|
('borg', 'create', '--list', '--filter', 'FOO'),
|
|
|
|
REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
flexmock(),
|
|
|
|
flexmock(),
|
|
|
|
)
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-04-04 23:23:56 +02:00
|
|
|
('borg', 'create', '--list', '--filter', 'FOO') + REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
output_log_level=module.borgmatic.logger.ANSWER,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2018-09-30 07:45:00 +02:00
|
|
|
)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2024-04-04 23:23:56 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
2017-08-06 01:21:39 +02:00
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-04-04 23:23:56 +02:00
|
|
|
list_files=True,
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2017-09-03 20:13:14 +02:00
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-04-04 23:23:56 +02:00
|
|
|
('borg', 'create', '--info', '--progress') + REPO_ARCHIVE_WITH_PATHS,
|
2019-12-01 01:55:05 +01:00
|
|
|
output_log_level=logging.INFO,
|
2024-04-04 23:23:56 +02:00
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2024-04-04 23:23:56 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2017-09-03 20:13:14 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2017-09-03 20:13:14 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-04-04 23:23:56 +02:00
|
|
|
progress=True,
|
2017-09-03 20:13:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_progress_calls_borg_with_progress_parameter():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2019-04-03 07:30:14 +02:00
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
2024-04-04 23:23:56 +02:00
|
|
|
('borg', 'create', '--progress') + REPO_ARCHIVE_WITH_PATHS,
|
2019-06-12 21:11:36 +02:00
|
|
|
output_log_level=logging.INFO,
|
2024-04-04 23:23:56 +02:00
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2019-04-03 07:30:14 +02:00
|
|
|
)
|
2017-09-03 20:13:14 +02:00
|
|
|
|
|
|
|
module.create_archive(
|
2018-01-16 05:55:27 +01:00
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2017-09-03 20:13:14 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-04-04 23:23:56 +02:00
|
|
|
progress=True,
|
2017-09-03 20:13:14 +02:00
|
|
|
)
|
2019-12-05 00:48:10 +01:00
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2024-04-04 23:23:56 +02:00
|
|
|
processes = flexmock()
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(
|
|
|
|
('borg', 'create', '--one-file-system', '--read-special'),
|
|
|
|
REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
flexmock(),
|
|
|
|
flexmock(),
|
|
|
|
)
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_special_file_paths').and_return(())
|
|
|
|
create_command = (
|
|
|
|
'borg',
|
|
|
|
'create',
|
|
|
|
'--one-file-system',
|
|
|
|
'--read-special',
|
|
|
|
'--progress',
|
|
|
|
) + REPO_ARCHIVE_WITH_PATHS
|
|
|
|
flexmock(module).should_receive('execute_command_with_processes').with_args(
|
|
|
|
create_command + ('--dry-run', '--list'),
|
|
|
|
processes=processes,
|
2020-11-18 19:58:23 +01:00
|
|
|
output_log_level=logging.INFO,
|
2024-04-04 23:23:56 +02:00
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('execute_command_with_processes').with_args(
|
|
|
|
create_command,
|
|
|
|
processes=processes,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=module.DO_NOT_CAPTURE,
|
2020-11-18 19:58:23 +01:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2020-11-18 19:58:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2024-04-04 23:23:56 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2020-11-18 19:58:23 +01:00
|
|
|
'source_directories': ['foo', 'bar'],
|
2024-04-04 23:23:56 +02:00
|
|
|
'repositories': ['repo'],
|
2020-11-18 19:58:23 +01:00
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-04-04 23:23:56 +02:00
|
|
|
progress=True,
|
|
|
|
stream_processes=processes,
|
2020-11-18 19:58:23 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_stream_processes_ands_read_special_false_excludes_special_files():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2024-04-04 23:23:56 +02:00
|
|
|
processes = flexmock()
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(
|
|
|
|
('borg', 'create', '--one-file-system', '--read-special'),
|
|
|
|
REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
flexmock(),
|
|
|
|
flexmock(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('collect_special_file_paths').and_return(('/dev/null',))
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_home_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('write_pattern_file').and_return(flexmock(name='patterns'))
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
create_command = (
|
|
|
|
'borg',
|
|
|
|
'create',
|
|
|
|
'--one-file-system',
|
|
|
|
'--read-special',
|
|
|
|
) + REPO_ARCHIVE_WITH_PATHS
|
|
|
|
flexmock(module).should_receive('execute_command_with_processes').with_args(
|
|
|
|
create_command + ('--dry-run', '--list'),
|
|
|
|
processes=processes,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=None,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('execute_command_with_processes').with_args(
|
|
|
|
create_command,
|
|
|
|
processes=processes,
|
2019-12-05 00:48:10 +01:00
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2019-12-05 00:48:10 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2019-12-05 00:48:10 +01:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
2024-04-04 23:23:56 +02:00
|
|
|
'read_special': False,
|
2019-12-05 00:48:10 +01:00
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2024-04-04 23:23:56 +02:00
|
|
|
stream_processes=processes,
|
2019-12-05 00:48:10 +01:00
|
|
|
)
|
2020-05-07 21:14:27 +02:00
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_stream_processes_and_read_special_true_skips_special_files_excludes():
|
2022-12-02 21:12:10 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2020-05-07 21:14:27 +02:00
|
|
|
processes = flexmock()
|
2022-03-07 20:58:29 +01:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(
|
|
|
|
('borg', 'create', '--one-file-system', '--read-special'),
|
|
|
|
REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
flexmock(),
|
|
|
|
flexmock(),
|
|
|
|
)
|
2022-08-14 07:50:14 +02:00
|
|
|
)
|
2022-06-30 22:42:17 +02:00
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('collect_special_file_paths').never()
|
2022-10-03 21:58:13 +02:00
|
|
|
create_command = (
|
|
|
|
'borg',
|
|
|
|
'create',
|
|
|
|
'--one-file-system',
|
|
|
|
'--read-special',
|
|
|
|
) + REPO_ARCHIVE_WITH_PATHS
|
|
|
|
flexmock(module).should_receive('execute_command_with_processes').with_args(
|
2024-04-04 23:23:56 +02:00
|
|
|
create_command + ('--dry-run', '--list'),
|
2022-10-03 21:58:13 +02:00
|
|
|
processes=processes,
|
|
|
|
output_log_level=logging.INFO,
|
|
|
|
output_file=None,
|
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2022-10-03 21:58:13 +02:00
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
)
|
2020-05-07 21:14:27 +02:00
|
|
|
flexmock(module).should_receive('execute_command_with_processes').with_args(
|
2022-10-03 21:58:13 +02:00
|
|
|
create_command,
|
2020-05-07 21:14:27 +02:00
|
|
|
processes=processes,
|
|
|
|
output_log_level=logging.INFO,
|
2020-05-10 06:53:16 +02:00
|
|
|
output_file=None,
|
2020-05-15 07:38:38 +02:00
|
|
|
borg_local_path='borg',
|
2024-01-21 20:34:40 +01:00
|
|
|
borg_exit_codes=None,
|
2021-12-10 18:24:41 +01:00
|
|
|
working_directory=None,
|
2022-06-30 22:42:17 +02:00
|
|
|
extra_environment=None,
|
2020-05-07 21:14:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
module.create_archive(
|
|
|
|
dry_run=False,
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path='repo',
|
2023-07-09 08:14:30 +02:00
|
|
|
config={
|
2020-05-07 21:14:27 +02:00
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
2024-04-04 23:23:56 +02:00
|
|
|
'read_special': True,
|
2020-05-07 21:14:27 +02:00
|
|
|
},
|
2024-01-09 22:47:20 +01:00
|
|
|
config_paths=['/tmp/test.yaml'],
|
2022-02-10 01:54:35 +01:00
|
|
|
local_borg_version='1.2.3',
|
2024-01-09 22:47:20 +01:00
|
|
|
global_arguments=flexmock(log_json=False),
|
2020-05-07 21:14:27 +02:00
|
|
|
stream_processes=processes,
|
|
|
|
)
|
2023-03-18 12:54:21 +01:00
|
|
|
|
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
def test_create_archive_with_json_calls_borg_with_json_flag():
|
2023-03-18 12:54:21 +01:00
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
2023-03-18 12:54:21 +01:00
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
2024-04-04 23:23:56 +02:00
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
|
|
|
)
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
|
('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
|
|
|
).and_return('[]')
|
2023-03-18 12:54:21 +01:00
|
|
|
|
2024-04-04 23:23:56 +02:00
|
|
|
json_output = module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo', 'bar'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
json=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_output == '[]'
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_archive_with_stats_and_json_calls_borg_without_stats_flag():
|
|
|
|
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
|
|
|
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
|
|
|
flexmock(module).should_receive('expand_directories').and_return(())
|
|
|
|
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
|
|
|
flexmock(module).should_receive('make_base_create_command').and_return(
|
|
|
|
(('borg', 'create'), REPO_ARCHIVE_WITH_PATHS, flexmock(), flexmock())
|
|
|
|
)
|
|
|
|
flexmock(module.environment).should_receive('make_environment')
|
|
|
|
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
|
('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS,
|
|
|
|
working_directory=None,
|
|
|
|
extra_environment=None,
|
|
|
|
borg_local_path='borg',
|
|
|
|
borg_exit_codes=None,
|
|
|
|
).and_return('[]')
|
|
|
|
|
|
|
|
json_output = module.create_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository_path='repo',
|
|
|
|
config={
|
|
|
|
'source_directories': ['foo*'],
|
|
|
|
'repositories': ['repo'],
|
|
|
|
'exclude_patterns': None,
|
|
|
|
},
|
|
|
|
config_paths=['/tmp/test.yaml'],
|
|
|
|
local_borg_version='1.2.3',
|
|
|
|
global_arguments=flexmock(log_json=False),
|
|
|
|
json=True,
|
|
|
|
stats=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_output == '[]'
|
2023-04-20 03:47:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_all_source_directories_exist_with_glob_and_tilde_directories():
|
|
|
|
flexmock(module).should_receive('expand_directory').with_args('foo*').and_return(
|
|
|
|
('foo', 'food')
|
|
|
|
)
|
|
|
|
flexmock(module).should_receive('expand_directory').with_args('~/bar').and_return(
|
|
|
|
('/root/bar',)
|
|
|
|
)
|
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(False)
|
|
|
|
flexmock(module.os.path).should_receive('exists').with_args('foo').and_return(True)
|
|
|
|
flexmock(module.os.path).should_receive('exists').with_args('food').and_return(True)
|
|
|
|
flexmock(module.os.path).should_receive('exists').with_args('/root/bar').and_return(True)
|
|
|
|
|
|
|
|
module.check_all_source_directories_exist(['foo*', '~/bar'])
|
2023-04-21 08:15:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_all_source_directories_exist_with_non_existent_directory_raises():
|
|
|
|
flexmock(module).should_receive('expand_directory').with_args('foo').and_return(('foo',))
|
|
|
|
flexmock(module.os.path).should_receive('exists').and_return(False)
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
module.check_all_source_directories_exist(['foo'])
|