actually test port restores

This commit is contained in:
Divyansh Singh 2023-06-19 01:10:01 +05:30
parent 384182172a
commit e2d82e9bba
3 changed files with 10 additions and 67 deletions

View file

@ -13,6 +13,7 @@ services:
POSTGRES_USER: postgres2 POSTGRES_USER: postgres2
ports: ports:
- "5433:5432" - "5433:5432"
command: -p 5433
mysql: mysql:
image: docker.io/mariadb:10.5 image: docker.io/mariadb:10.5
environment: environment:
@ -25,6 +26,7 @@ services:
MYSQL_DATABASE: test MYSQL_DATABASE: test
ports: ports:
- "3307:3306" - "3307:3306"
command: --port=3307
mongodb: mongodb:
image: docker.io/mongo:5.0.5 image: docker.io/mongo:5.0.5
environment: environment:
@ -37,6 +39,7 @@ services:
MONGO_INITDB_ROOT_PASSWORD: test2 MONGO_INITDB_ROOT_PASSWORD: test2
ports: ports:
- "27018:27017" - "27018:27017"
command: --port=27018
tests: tests:
image: docker.io/alpine:3.13 image: docker.io/alpine:3.13
environment: environment:

View file

@ -114,7 +114,7 @@ hooks:
password: test password: test
format: {postgresql_dump_format} format: {postgresql_dump_format}
restore_hostname: postgresql2 restore_hostname: postgresql2
restore_port: 5432 restore_port: 5433
restore_username: postgres2 restore_username: postgres2
restore_password: test2 restore_password: test2
mysql_databases: mysql_databases:
@ -123,7 +123,7 @@ hooks:
username: root username: root
password: test password: test
restore_hostname: mysql2 restore_hostname: mysql2
restore_port: 3306 restore_port: 3307
restore_username: root restore_username: root
restore_password: test2 restore_password: test2
mongodb_databases: mongodb_databases:
@ -134,7 +134,7 @@ hooks:
authentication_database: admin authentication_database: admin
format: {mongodb_dump_format} format: {mongodb_dump_format}
restore_hostname: mongodb2 restore_hostname: mongodb2
restore_port: 27017 restore_port: 27018
restore_username: root2 restore_username: root2
restore_password: test2 restore_password: test2
sqlite_databases: sqlite_databases:
@ -147,7 +147,7 @@ hooks:
config_file.write(config) config_file.write(config)
def write_custom_restore_configuration_for_cli_arguments( def write_simple_custom_restore_configuration(
source_directory, source_directory,
config_path, config_path,
repository_path, repository_path,
@ -233,14 +233,11 @@ def test_database_dump_and_restore_with_restore_cli_arguments():
repository_path = os.path.join(temporary_directory, 'test.borg') repository_path = os.path.join(temporary_directory, 'test.borg')
borgmatic_source_directory = os.path.join(temporary_directory, '.borgmatic') borgmatic_source_directory = os.path.join(temporary_directory, '.borgmatic')
# Write out a special file to ensure that it gets properly excluded and Borg doesn't hang on it.
os.mkfifo(os.path.join(temporary_directory, 'special_file'))
original_working_directory = os.getcwd() original_working_directory = os.getcwd()
try: try:
config_path = os.path.join(temporary_directory, 'test.yaml') config_path = os.path.join(temporary_directory, 'test.yaml')
write_custom_restore_configuration_for_cli_arguments( write_simple_custom_restore_configuration(
temporary_directory, config_path, repository_path, borgmatic_source_directory temporary_directory, config_path, repository_path, borgmatic_source_directory
) )
@ -275,7 +272,7 @@ def test_database_dump_and_restore_with_restore_cli_arguments():
'--hostname', '--hostname',
'postgresql2', 'postgresql2',
'--port', '--port',
'5432', '5433',
'--username', '--username',
'postgres2', 'postgres2',
'--password', '--password',
@ -287,15 +284,12 @@ def test_database_dump_and_restore_with_restore_cli_arguments():
shutil.rmtree(temporary_directory) shutil.rmtree(temporary_directory)
def test_database_dump_and_restore_to_different_hostname_port_username_password(): def test_database_dump_and_restore_with_restore_configuration_options():
# Create a Borg repository. # Create a Borg repository.
temporary_directory = tempfile.mkdtemp() temporary_directory = tempfile.mkdtemp()
repository_path = os.path.join(temporary_directory, 'test.borg') repository_path = os.path.join(temporary_directory, 'test.borg')
borgmatic_source_directory = os.path.join(temporary_directory, '.borgmatic') borgmatic_source_directory = os.path.join(temporary_directory, '.borgmatic')
# Write out a special file to ensure that it gets properly excluded and Borg doesn't hang on it.
os.mkfifo(os.path.join(temporary_directory, 'special_file'))
original_working_directory = os.getcwd() original_working_directory = os.getcwd()
try: try:

View file

@ -800,60 +800,6 @@ def test_restore_database_dump_without_connection_params_uses_restore_params_in_
) )
def test_restore_database_dump_with_no_passwords_runs_pg_restore_without_password():
database_config = [{'name': 'foo', 'username': 'postgres', 'schemas': None}]
extract_process = flexmock(stdout=flexmock())
flexmock(module).should_receive('make_dump_path')
flexmock(module.dump).should_receive('make_database_dump_filename')
flexmock(module).should_receive('execute_command_with_processes').with_args(
(
'pg_restore',
'--no-password',
'--if-exists',
'--exit-on-error',
'--clean',
'--dbname',
'foo',
'--username',
'postgres',
),
processes=[extract_process],
output_log_level=logging.DEBUG,
input_file=extract_process.stdout,
extra_environment={'PGSSLMODE': 'disable'},
).once()
flexmock(module).should_receive('execute_command').with_args(
(
'psql',
'--no-password',
'--no-psqlrc',
'--quiet',
'--username',
'postgres',
'--dbname',
'foo',
'--command',
'ANALYZE',
),
extra_environment={'PGSSLMODE': 'disable'},
).once()
module.restore_database_dump(
database_config,
'test.yaml',
{},
dry_run=False,
extract_process=extract_process,
connection_params={
'hostname': None,
'port': None,
'username': None,
'password': None,
},
)
def test_restore_database_dump_runs_pg_restore_with_options(): def test_restore_database_dump_runs_pg_restore_with_options():
database_config = [ database_config = [
{ {