|
@@ -466,20 +466,26 @@ def test_collect_dumps_from_archive_with_dumps_metadata_parses_it():
|
|
|
flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
'make_data_source_dump_path',
|
|
|
).and_return('')
|
|
|
- flexmock(module.borgmatic.config.paths).should_receive('make_runtime_directory_glob').and_return('')
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
+ 'make_runtime_directory_glob'
|
|
|
+ ).and_return('')
|
|
|
flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return(
|
|
|
[
|
|
|
'borgmatic/postgresql_databases/dumps.json',
|
|
|
'borgmatic/mysql_databases/dumps.json',
|
|
|
],
|
|
|
)
|
|
|
- flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').and_return(flexmock(stdout=flexmock(read=lambda: b'')))
|
|
|
+ flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').and_return(
|
|
|
+ flexmock(stdout=flexmock(read=lambda: b''))
|
|
|
+ )
|
|
|
dumps_metadata = [
|
|
|
module.Dump('postgresql_databases', 'foo'),
|
|
|
module.Dump('postgresql_databases', 'bar', 'host', 1234),
|
|
|
module.Dump('mysql_databases', 'quux'),
|
|
|
]
|
|
|
- flexmock(module.borgmatic.hooks.data_source.dump).should_receive('parse_data_source_dumps_metadata').and_return(dumps_metadata)
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
+ 'parse_data_source_dumps_metadata'
|
|
|
+ ).and_return(dumps_metadata)
|
|
|
flexmock(module.borgmatic.config.paths).should_receive('get_borgmatic_source_directory').never()
|
|
|
|
|
|
archive_dumps = module.collect_dumps_from_archive(
|
|
@@ -496,9 +502,55 @@ def test_collect_dumps_from_archive_with_dumps_metadata_parses_it():
|
|
|
assert archive_dumps == set(dumps_metadata)
|
|
|
|
|
|
|
|
|
+def test_collect_dumps_from_archive_with_empty_dumps_metadata_path_falls_back_to_parsing_archive_paths():
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
+ 'make_runtime_directory_glob'
|
|
|
+ ).and_return('')
|
|
|
+ flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return(
|
|
|
+ ['']
|
|
|
+ ).and_return(
|
|
|
+ [
|
|
|
+ 'borgmatic/postgresql_databases/localhost/foo',
|
|
|
+ 'borgmatic/postgresql_databases/host:1234/bar',
|
|
|
+ 'borgmatic/mysql_databases/localhost/quux',
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').never()
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
+ 'parse_data_source_dumps_metadata'
|
|
|
+ ).never()
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
+ 'get_borgmatic_source_directory',
|
|
|
+ ).and_return('/root/.borgmatic')
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
+ 'make_data_source_dump_path',
|
|
|
+ ).and_return('')
|
|
|
+
|
|
|
+ archive_dumps = module.collect_dumps_from_archive(
|
|
|
+ repository={'path': 'repo'},
|
|
|
+ archive='archive',
|
|
|
+ config={},
|
|
|
+ local_borg_version=flexmock(),
|
|
|
+ global_arguments=flexmock(dry_run=False, log_json=False),
|
|
|
+ local_path=flexmock(),
|
|
|
+ remote_path=flexmock(),
|
|
|
+ borgmatic_runtime_directory='/run/borgmatic',
|
|
|
+ )
|
|
|
+
|
|
|
+ assert archive_dumps == {
|
|
|
+ module.Dump('postgresql_databases', 'foo'),
|
|
|
+ module.Dump('postgresql_databases', 'bar', 'host', 1234),
|
|
|
+ module.Dump('mysql_databases', 'quux'),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
def test_collect_dumps_from_archive_without_dumps_metadata_falls_back_to_parsing_archive_paths():
|
|
|
- flexmock(module.borgmatic.config.paths).should_receive('make_runtime_directory_glob').and_return('')
|
|
|
- flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return([]).and_return(
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
+ 'make_runtime_directory_glob'
|
|
|
+ ).and_return('')
|
|
|
+ flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return(
|
|
|
+ []
|
|
|
+ ).and_return(
|
|
|
[
|
|
|
'borgmatic/postgresql_databases/localhost/foo',
|
|
|
'borgmatic/postgresql_databases/host:1234/bar',
|
|
@@ -506,7 +558,9 @@ def test_collect_dumps_from_archive_without_dumps_metadata_falls_back_to_parsing
|
|
|
],
|
|
|
)
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').never()
|
|
|
- flexmock(module.borgmatic.hooks.data_source.dump).should_receive('parse_data_source_dumps_metadata').never()
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
+ 'parse_data_source_dumps_metadata'
|
|
|
+ ).never()
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'get_borgmatic_source_directory',
|
|
|
).and_return('/root/.borgmatic')
|
|
@@ -533,8 +587,12 @@ def test_collect_dumps_from_archive_without_dumps_metadata_falls_back_to_parsing
|
|
|
|
|
|
|
|
|
def test_collect_dumps_from_archive_parses_archive_paths_with_different_base_directories():
|
|
|
- flexmock(module.borgmatic.config.paths).should_receive('make_runtime_directory_glob').and_return('')
|
|
|
- flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return([]).and_return(
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
+ 'make_runtime_directory_glob'
|
|
|
+ ).and_return('')
|
|
|
+ flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return(
|
|
|
+ []
|
|
|
+ ).and_return(
|
|
|
[
|
|
|
'borgmatic/postgresql_databases/localhost/foo',
|
|
|
'.borgmatic/postgresql_databases/localhost/bar',
|
|
@@ -543,7 +601,9 @@ def test_collect_dumps_from_archive_parses_archive_paths_with_different_base_dir
|
|
|
],
|
|
|
)
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').never()
|
|
|
- flexmock(module.borgmatic.hooks.data_source.dump).should_receive('parse_data_source_dumps_metadata').never()
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
+ 'parse_data_source_dumps_metadata'
|
|
|
+ ).never()
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'get_borgmatic_source_directory',
|
|
|
).and_return('/root/.borgmatic')
|
|
@@ -571,15 +631,21 @@ def test_collect_dumps_from_archive_parses_archive_paths_with_different_base_dir
|
|
|
|
|
|
|
|
|
def test_collect_dumps_from_archive_parses_directory_format_archive_paths():
|
|
|
- flexmock(module.borgmatic.config.paths).should_receive('make_runtime_directory_glob').and_return('')
|
|
|
- flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return([]).and_return(
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
+ 'make_runtime_directory_glob'
|
|
|
+ ).and_return('')
|
|
|
+ flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return(
|
|
|
+ []
|
|
|
+ ).and_return(
|
|
|
[
|
|
|
'borgmatic/postgresql_databases/localhost/foo/table1',
|
|
|
'borgmatic/postgresql_databases/localhost/foo/table2',
|
|
|
],
|
|
|
)
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').never()
|
|
|
- flexmock(module.borgmatic.hooks.data_source.dump).should_receive('parse_data_source_dumps_metadata').never()
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
+ 'parse_data_source_dumps_metadata'
|
|
|
+ ).never()
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'get_borgmatic_source_directory',
|
|
|
).and_return('/root/.borgmatic')
|
|
@@ -604,8 +670,12 @@ def test_collect_dumps_from_archive_parses_directory_format_archive_paths():
|
|
|
|
|
|
|
|
|
def test_collect_dumps_from_archive_skips_bad_archive_paths_or_bad_path_components():
|
|
|
- flexmock(module.borgmatic.config.paths).should_receive('make_runtime_directory_glob').and_return('')
|
|
|
- flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return([]).and_return(
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
+ 'make_runtime_directory_glob'
|
|
|
+ ).and_return('')
|
|
|
+ flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return(
|
|
|
+ []
|
|
|
+ ).and_return(
|
|
|
[
|
|
|
'borgmatic/postgresql_databases/localhost/foo',
|
|
|
'borgmatic/postgresql_databases/localhost:abcd/bar',
|
|
@@ -615,7 +685,9 @@ def test_collect_dumps_from_archive_skips_bad_archive_paths_or_bad_path_componen
|
|
|
],
|
|
|
)
|
|
|
flexmock(module.borgmatic.borg.extract).should_receive('extract_archive').never()
|
|
|
- flexmock(module.borgmatic.hooks.data_source.dump).should_receive('parse_data_source_dumps_metadata').never()
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
|
|
|
+ 'parse_data_source_dumps_metadata'
|
|
|
+ ).never()
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'get_borgmatic_source_directory',
|
|
|
).and_return('/root/.borgmatic')
|