Add database restore overrides to NEWS, add a test, and move some tests (#326).

This commit is contained in:
Dan Helfman 2023-06-22 12:40:57 -07:00
parent 9e0df595c8
commit 69611681e2
3 changed files with 47 additions and 33 deletions

2
NEWS
View file

@ -1,4 +1,6 @@
1.7.15.dev0 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. * #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 * #529: Remove upgrade-borgmatic-config command for upgrading borgmatic 1.1.0 INI-style
configuration. configuration.

View file

@ -6,6 +6,50 @@ from flexmock import flexmock
from borgmatic.hooks import postgresql as module 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(): def test_database_names_to_dump_passes_through_individual_database_name():
database = {'name': 'foo'} 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] 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(): def test_dump_databases_runs_pg_dump_with_directory_format():
databases = [{'name': 'foo', 'format': 'directory'}] databases = [{'name': 'foo', 'format': 'directory'}]
flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'}) 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(): def test_restore_database_dump_with_connection_params_uses_connection_params_for_restore():
database_config = [ database_config = [
{ {

View file

@ -1,4 +1,5 @@
import logging import logging
import pytest import pytest
from flexmock import flexmock from flexmock import flexmock