diff --git a/NEWS b/NEWS index b6939ffa..7e78c131 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ 1.7.15.dev0 + * #326: Add configuration options and command-line flags for backing up a database from one + location while restoring it somewhere else. * #399: Add a documentation troubleshooting note for MySQL/MariaDB authentication errors. * #529: Remove upgrade-borgmatic-config command for upgrading borgmatic 1.1.0 INI-style configuration. diff --git a/tests/unit/hooks/test_postgresql.py b/tests/unit/hooks/test_postgresql.py index e48258ee..7ba45847 100644 --- a/tests/unit/hooks/test_postgresql.py +++ b/tests/unit/hooks/test_postgresql.py @@ -6,6 +6,50 @@ from flexmock import flexmock from borgmatic.hooks import postgresql as module +def test_make_extra_environment_maps_options_to_environment(): + database = { + 'name': 'foo', + 'password': 'pass', + 'ssl_mode': 'require', + 'ssl_cert': 'cert.crt', + 'ssl_key': 'key.key', + 'ssl_root_cert': 'root.crt', + 'ssl_crl': 'crl.crl', + } + expected = { + 'PGPASSWORD': 'pass', + 'PGSSLMODE': 'require', + 'PGSSLCERT': 'cert.crt', + 'PGSSLKEY': 'key.key', + 'PGSSLROOTCERT': 'root.crt', + 'PGSSLCRL': 'crl.crl', + } + + extra_env = module.make_extra_environment(database) + + assert extra_env == expected + + +def test_make_extra_environment_with_cli_password_sets_correct_password(): + database = {'name': 'foo', 'restore_password': 'trustsome1', 'password': 'anotherpassword'} + + extra = module.make_extra_environment( + database, restore_connection_params={'password': 'clipassword'} + ) + + assert extra['PGPASSWORD'] == 'clipassword' + + +def test_make_extra_environment_without_cli_password_or_configured_password_does_not_set_password(): + database = {'name': 'foo'} + + extra = module.make_extra_environment( + database, restore_connection_params={'username': 'someone'} + ) + + assert 'PGPASSWORD' not in extra + + def test_database_names_to_dump_passes_through_individual_database_name(): database = {'name': 'foo'} @@ -301,29 +345,6 @@ def test_dump_databases_runs_pg_dump_with_username_and_password(): assert module.dump_databases(databases, 'test.yaml', {}, dry_run=False) == [process] -def test_make_extra_environment_maps_options_to_environment(): - database = { - 'name': 'foo', - 'password': 'pass', - 'ssl_mode': 'require', - 'ssl_cert': 'cert.crt', - 'ssl_key': 'key.key', - 'ssl_root_cert': 'root.crt', - 'ssl_crl': 'crl.crl', - } - expected = { - 'PGPASSWORD': 'pass', - 'PGSSLMODE': 'require', - 'PGSSLCERT': 'cert.crt', - 'PGSSLKEY': 'key.key', - 'PGSSLROOTCERT': 'root.crt', - 'PGSSLCRL': 'crl.crl', - } - - extra_env = module.make_extra_environment(database) - assert extra_env == expected - - def test_dump_databases_runs_pg_dump_with_directory_format(): databases = [{'name': 'foo', 'format': 'directory'}] flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'}) @@ -638,16 +659,6 @@ def test_restore_database_dump_runs_pg_restore_with_username_and_password(): ) -def test_make_extra_environment_with_cli_password_sets_correct_password(): - database = {'name': 'foo', 'restore_password': 'trustsome1', 'password': 'anotherpassword'} - - extra = module.make_extra_environment( - database, restore_connection_params={'password': 'clipassword'} - ) - - assert extra['PGPASSWORD'] == 'clipassword' - - def test_restore_database_dump_with_connection_params_uses_connection_params_for_restore(): database_config = [ { diff --git a/tests/unit/hooks/test_sqlite.py b/tests/unit/hooks/test_sqlite.py index 5820713b..33317372 100644 --- a/tests/unit/hooks/test_sqlite.py +++ b/tests/unit/hooks/test_sqlite.py @@ -1,4 +1,5 @@ import logging + import pytest from flexmock import flexmock