diff --git a/tests/unit/actions/test_restore.py b/tests/unit/actions/test_restore.py index 5ad1d4d5..9941fdb3 100644 --- a/tests/unit/actions/test_restore.py +++ b/tests/unit/actions/test_restore.py @@ -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,13 @@ def test_collect_dumps_from_archive_with_dumps_metadata_parses_it(): assert archive_dumps == set(dumps_metadata) -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( +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', @@ -506,7 +516,51 @@ 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') + 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( + [ + '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') @@ -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') diff --git a/tests/unit/hooks/data_source/test_mariadb.py b/tests/unit/hooks/data_source/test_mariadb.py index 184a0ff9..922d5e1c 100644 --- a/tests/unit/hooks/data_source/test_mariadb.py +++ b/tests/unit/hooks/data_source/test_mariadb.py @@ -355,7 +355,7 @@ def test_dump_data_sources_dumps_each_database(): [ module.borgmatic.actions.restore.Dump('mariadb_databases', 'foo'), module.borgmatic.actions.restore.Dump('mariadb_databases', 'bar'), - ] + ], ).once() assert ( @@ -404,7 +404,7 @@ def test_dump_data_sources_dumps_with_password(): 'mariadb_databases', [ module.borgmatic.actions.restore.Dump('mariadb_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -455,7 +455,7 @@ def test_dump_data_sources_dumps_with_environment_password_transport_passes_pass 'mariadb_databases', [ module.borgmatic.actions.restore.Dump('mariadb_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -493,7 +493,7 @@ def test_dump_data_sources_dumps_all_databases_at_once(): 'mariadb_databases', [ module.borgmatic.actions.restore.Dump('mariadb_databases', 'all'), - ] + ], ).once() assert module.dump_data_sources( @@ -535,7 +535,7 @@ def test_dump_data_sources_dumps_all_databases_separately_when_format_configured [ module.borgmatic.actions.restore.Dump('mariadb_databases', 'foo'), module.borgmatic.actions.restore.Dump('mariadb_databases', 'bar'), - ] + ], ).once() assert ( diff --git a/tests/unit/hooks/data_source/test_mongodb.py b/tests/unit/hooks/data_source/test_mongodb.py index 8ac97c11..98f5ae2e 100644 --- a/tests/unit/hooks/data_source/test_mongodb.py +++ b/tests/unit/hooks/data_source/test_mongodb.py @@ -45,7 +45,7 @@ def test_dump_data_sources_runs_mongodump_for_each_database(): [ module.borgmatic.actions.restore.Dump('mongodb_databases', 'foo'), module.borgmatic.actions.restore.Dump('mongodb_databases', 'bar'), - ] + ], ).once() assert ( @@ -113,8 +113,10 @@ def test_dump_data_sources_runs_mongodump_with_hostname_and_port(): '/run/borgmatic', 'mongodb_databases', [ - module.borgmatic.actions.restore.Dump('mongodb_databases', 'foo', 'database.example.org', 27018), - ] + module.borgmatic.actions.restore.Dump( + 'mongodb_databases', 'foo', 'database.example.org', 27018 + ), + ], ).once() assert module.dump_data_sources( @@ -172,7 +174,7 @@ def test_dump_data_sources_runs_mongodump_with_username_and_password(): 'mongodb_databases', [ module.borgmatic.actions.restore.Dump('mongodb_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -203,7 +205,7 @@ def test_dump_data_sources_runs_mongodump_with_directory_format(): 'mongodb_databases', [ module.borgmatic.actions.restore.Dump('mongodb_databases', 'foo'), - ] + ], ).once() assert ( @@ -246,7 +248,7 @@ def test_dump_data_sources_runs_mongodump_with_options(): 'mongodb_databases', [ module.borgmatic.actions.restore.Dump('mongodb_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -278,7 +280,7 @@ def test_dump_data_sources_runs_mongodumpall_for_all_databases(): 'mongodb_databases', [ module.borgmatic.actions.restore.Dump('mongodb_databases', 'all'), - ] + ], ).once() assert module.dump_data_sources( @@ -758,7 +760,7 @@ def test_dump_data_sources_uses_custom_mongodump_command(): 'mongodb_databases', [ module.borgmatic.actions.restore.Dump('mongodb_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( diff --git a/tests/unit/hooks/data_source/test_mysql.py b/tests/unit/hooks/data_source/test_mysql.py index 904282c2..f9cbe099 100644 --- a/tests/unit/hooks/data_source/test_mysql.py +++ b/tests/unit/hooks/data_source/test_mysql.py @@ -238,7 +238,7 @@ def test_dump_data_sources_dumps_each_database(): [ module.borgmatic.actions.restore.Dump('mysql_databases', 'foo'), module.borgmatic.actions.restore.Dump('mysql_databases', 'bar'), - ] + ], ).once() assert ( @@ -287,7 +287,7 @@ def test_dump_data_sources_dumps_with_password(): 'mysql_databases', [ module.borgmatic.actions.restore.Dump('mysql_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -338,7 +338,7 @@ def test_dump_data_sources_dumps_with_environment_password_transport_passes_pass 'mysql_databases', [ module.borgmatic.actions.restore.Dump('mysql_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -377,7 +377,7 @@ def test_dump_data_sources_dumps_all_databases_at_once(): 'mysql_databases', [ module.borgmatic.actions.restore.Dump('mysql_databases', 'all'), - ] + ], ).once() assert module.dump_data_sources( @@ -419,7 +419,7 @@ def test_dump_data_sources_dumps_all_databases_separately_when_format_configured [ module.borgmatic.actions.restore.Dump('mysql_databases', 'foo'), module.borgmatic.actions.restore.Dump('mysql_databases', 'bar'), - ] + ], ).once() assert ( diff --git a/tests/unit/hooks/data_source/test_postgresql.py b/tests/unit/hooks/data_source/test_postgresql.py index 0971f6b9..22f7ee4c 100644 --- a/tests/unit/hooks/data_source/test_postgresql.py +++ b/tests/unit/hooks/data_source/test_postgresql.py @@ -279,7 +279,7 @@ def test_dump_data_sources_runs_pg_dump_for_each_database(): [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), module.borgmatic.actions.restore.Dump('postgresql_databases', 'bar'), - ] + ], ).once() assert ( @@ -350,7 +350,7 @@ def test_dump_data_sources_with_duplicate_dump_skips_pg_dump(): [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), module.borgmatic.actions.restore.Dump('postgresql_databases', 'bar'), - ] + ], ).once() assert ( @@ -436,8 +436,10 @@ def test_dump_data_sources_runs_pg_dump_with_hostname_and_port(): '/run/borgmatic', 'postgresql_databases', [ - module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo', 'database.example.org', 5433), - ] + module.borgmatic.actions.restore.Dump( + 'postgresql_databases', 'foo', 'database.example.org', 5433 + ), + ], ).once() assert module.dump_data_sources( @@ -490,7 +492,7 @@ def test_dump_data_sources_runs_pg_dump_with_username_and_password(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -543,7 +545,7 @@ def test_dump_data_sources_with_username_injection_attack_gets_escaped(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -591,7 +593,7 @@ def test_dump_data_sources_runs_pg_dump_with_directory_format(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), - ] + ], ).once() assert ( @@ -645,7 +647,7 @@ def test_dump_data_sources_runs_pg_dump_with_string_compression(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), - ] + ], ).once() assert ( @@ -699,7 +701,7 @@ def test_dump_data_sources_runs_pg_dump_with_integer_compression(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), - ] + ], ).once() assert ( @@ -752,7 +754,7 @@ def test_dump_data_sources_runs_pg_dump_with_options(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( @@ -791,7 +793,7 @@ def test_dump_data_sources_runs_pg_dumpall_for_all_databases(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'all'), - ] + ], ).once() assert module.dump_data_sources( @@ -842,7 +844,7 @@ def test_dump_data_sources_runs_non_default_pg_dump(): 'postgresql_databases', [ module.borgmatic.actions.restore.Dump('postgresql_databases', 'foo'), - ] + ], ).once() assert module.dump_data_sources( diff --git a/tests/unit/hooks/data_source/test_sqlite.py b/tests/unit/hooks/data_source/test_sqlite.py index e1dcd510..3531c975 100644 --- a/tests/unit/hooks/data_source/test_sqlite.py +++ b/tests/unit/hooks/data_source/test_sqlite.py @@ -31,7 +31,7 @@ def test_dump_data_sources_logs_and_skips_if_dump_already_exists(): 'sqlite_databases', [ module.borgmatic.actions.restore.Dump('sqlite_databases', 'database'), - ] + ], ).once() assert ( @@ -69,7 +69,7 @@ def test_dump_data_sources_dumps_each_database(): [ module.borgmatic.actions.restore.Dump('sqlite_databases', 'database1'), module.borgmatic.actions.restore.Dump('sqlite_databases', 'database2'), - ] + ], ).once() assert ( @@ -113,7 +113,7 @@ def test_dump_data_sources_with_path_injection_attack_gets_escaped(): 'sqlite_databases', [ module.borgmatic.actions.restore.Dump('sqlite_databases', 'database1'), - ] + ], ).once() assert ( @@ -162,7 +162,7 @@ def test_dump_data_sources_runs_non_default_sqlite_with_path_injection_attack_ge 'sqlite_databases', [ module.borgmatic.actions.restore.Dump('sqlite_databases', 'database1'), - ] + ], ).once() assert ( @@ -197,7 +197,7 @@ def test_dump_data_sources_with_non_existent_path_warns_and_dumps_database(): 'sqlite_databases', [ module.borgmatic.actions.restore.Dump('sqlite_databases', 'database1'), - ] + ], ).once() assert ( @@ -234,7 +234,7 @@ def test_dump_data_sources_with_name_all_warns_and_dumps_all_databases(): 'sqlite_databases', [ module.borgmatic.actions.restore.Dump('sqlite_databases', 'all'), - ] + ], ).once() assert (