Browse Source

Mock `get_working_directory()` calls in data source hook tests

bockulator 3 weeks ago
parent
commit
ce7f0226be

+ 29 - 1
tests/unit/hooks/data_source/test_mariadb.py

@@ -186,6 +186,9 @@ def test_database_names_to_dump_queries_mariadb_for_database_names():
         'trustsome1',
         'trustsome1',
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
+        '/path/to/working/dir'
+    )
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -196,7 +199,7 @@ def test_database_names_to_dump_queries_mariadb_for_database_names():
             'show schemas',
             'show schemas',
         ),
         ),
         environment=environment,
         environment=environment,
-        working_directory=None,
+        working_directory='/path/to/working/dir',
     ).and_return('foo\nbar\nmysql\n').once()
     ).and_return('foo\nbar\nmysql\n').once()
 
 
     names = module.database_names_to_dump(
     names = module.database_names_to_dump(
@@ -222,6 +225,7 @@ def test_database_names_to_dump_with_database_name_all_and_skip_names_filters_ou
         'trustsome1',
         'trustsome1',
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -254,6 +258,7 @@ def test_database_names_to_dump_with_environment_password_transport_skips_defaul
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module).should_receive('parse_extra_options').and_return((), None)
     flexmock(module).should_receive('parse_extra_options').and_return((), None)
     flexmock(module).should_receive('make_defaults_file_options').never()
     flexmock(module).should_receive('make_defaults_file_options').never()
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -291,6 +296,7 @@ def test_database_names_to_dump_runs_mariadb_with_tls():
         'trustsome1',
         'trustsome1',
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -328,6 +334,7 @@ def test_database_names_to_dump_runs_mariadb_without_tls():
         'trustsome1',
         'trustsome1',
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -704,6 +711,7 @@ def test_database_names_to_dump_runs_mariadb_with_list_options():
         'trustsome1',
         'trustsome1',
         'mariadb.cnf',
         'mariadb.cnf',
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -739,6 +747,7 @@ def test_database_names_to_dump_runs_non_default_mariadb_with_list_options():
         'trustsome1',
         'trustsome1',
         'mariadb.cnf',
         'mariadb.cnf',
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         environment=None,
         environment=None,
         full_command=(
         full_command=(
@@ -773,6 +782,7 @@ def test_execute_dump_command_runs_mariadb_dump():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -815,6 +825,7 @@ def test_execute_dump_command_with_environment_password_transport_skips_defaults
     flexmock(module).should_receive('parse_extra_options').and_return((), None)
     flexmock(module).should_receive('parse_extra_options').and_return((), None)
     flexmock(module).should_receive('make_defaults_file_options').never()
     flexmock(module).should_receive('make_defaults_file_options').never()
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -862,6 +873,7 @@ def test_execute_dump_command_runs_mariadb_dump_without_add_drop_database():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -907,6 +919,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_hostname_and_port():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -959,6 +972,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_tls():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -1006,6 +1020,7 @@ def test_execute_dump_command_runs_mariadb_dump_without_tls():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -1053,6 +1068,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_username_and_password():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -1099,6 +1115,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_options():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -1146,6 +1163,7 @@ def test_execute_dump_command_runs_non_default_mariadb_dump_with_options():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -1257,6 +1275,7 @@ def test_restore_data_source_dump_runs_mariadb_to_restore():
         None,
         None,
     ).and_return(())
     ).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mariadb', '--batch'),
         ('mariadb', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1296,6 +1315,7 @@ def test_restore_data_source_dump_runs_mariadb_with_options():
         None,
         None,
     ).and_return(())
     ).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mariadb', '--harder', '--batch'),
         ('mariadb', '--harder', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1337,6 +1357,7 @@ def test_restore_data_source_dump_runs_non_default_mariadb_with_options():
         None,
         None,
     ).and_return(())
     ).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('custom_mariadb', '--harder', '--batch'),
         ('custom_mariadb', '--harder', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1376,6 +1397,7 @@ def test_restore_data_source_dump_runs_mariadb_with_hostname_and_port():
         None,
         None,
     ).and_return(())
     ).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -1424,6 +1446,7 @@ def test_restore_data_source_dump_runs_mariadb_with_tls():
         None,
         None,
     ).and_return(())
     ).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -1467,6 +1490,7 @@ def test_restore_data_source_dump_runs_mariadb_without_tls():
         None,
         None,
     ).and_return(())
     ).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -1510,6 +1534,7 @@ def test_restore_data_source_dump_runs_mariadb_with_username_and_password():
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mariadb', '--defaults-extra-file=/dev/fd/99', '--batch'),
         ('mariadb', '--defaults-extra-file=/dev/fd/99', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1554,6 +1579,7 @@ def test_restore_data_source_with_environment_password_transport_skips_defaults_
     flexmock(module.os).should_receive('environ').and_return(
     flexmock(module.os).should_receive('environ').and_return(
         {'USER': 'root', 'MYSQL_PWD': 'trustsome1'},
         {'USER': 'root', 'MYSQL_PWD': 'trustsome1'},
     )
     )
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mariadb', '--batch', '--user', 'root'),
         ('mariadb', '--batch', '--user', 'root'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1603,6 +1629,7 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mariadb',
             'mariadb',
@@ -1666,6 +1693,7 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mariadb',
             'mariadb',

+ 20 - 1
tests/unit/hooks/data_source/test_mongodb.py

@@ -31,13 +31,16 @@ def test_dump_data_sources_runs_mongodump_for_each_database():
         'databases/localhost/foo',
         'databases/localhost/foo',
     ).and_return('databases/localhost/bar')
     ).and_return('databases/localhost/bar')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
+        '/path/to/working/dir'
+    )
 
 
     for name, process in zip(('foo', 'bar'), processes):
     for name, process in zip(('foo', 'bar'), processes):
         flexmock(module).should_receive('execute_command').with_args(
         flexmock(module).should_receive('execute_command').with_args(
             ('mongodump', '--db', name, '--archive', '>', f'databases/localhost/{name}'),
             ('mongodump', '--db', name, '--archive', '>', f'databases/localhost/{name}'),
             shell=True,
             shell=True,
             run_to_completion=False,
             run_to_completion=False,
-            working_directory=None,
+            working_directory='/path/to/working/dir',
         ).and_return(process).once()
         ).and_return(process).once()
 
 
     flexmock(module.dump).should_receive('write_data_source_dumps_metadata').with_args(
     flexmock(module.dump).should_receive('write_data_source_dumps_metadata').with_args(
@@ -101,6 +104,7 @@ def test_dump_data_sources_runs_mongodump_with_hostname_and_port():
         'databases/database.example.org/foo',
         'databases/database.example.org/foo',
     )
     )
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -167,6 +171,7 @@ def test_dump_data_sources_runs_mongodump_with_username_and_password():
         '/dev/fd/99',
         '/dev/fd/99',
     )
     )
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -220,6 +225,7 @@ def test_dump_data_sources_runs_mongodump_with_directory_format():
     )
     )
     flexmock(module.dump).should_receive('create_parent_directory_for_dump')
     flexmock(module.dump).should_receive('create_parent_directory_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
     flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('mongodump', '--out', 'databases/localhost/foo', '--db', 'foo'),
         ('mongodump', '--out', 'databases/localhost/foo', '--db', 'foo'),
@@ -262,6 +268,7 @@ def test_dump_data_sources_runs_mongodump_with_options():
         'databases/localhost/foo',
         'databases/localhost/foo',
     )
     )
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -310,6 +317,7 @@ def test_dump_data_sources_runs_mongodumpall_for_all_databases():
         'databases/localhost/all',
         'databases/localhost/all',
     )
     )
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('mongodump', '--archive', '>', 'databases/localhost/all'),
         ('mongodump', '--archive', '>', 'databases/localhost/all'),
@@ -379,6 +387,7 @@ def test_restore_data_source_dump_runs_mongorestore():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ['mongorestore', '--archive', '--drop'],
         ['mongorestore', '--archive', '--drop'],
         processes=[extract_process],
         processes=[extract_process],
@@ -414,6 +423,7 @@ def test_restore_data_source_dump_runs_mongorestore_with_hostname_and_port():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         [
         [
             'mongorestore',
             'mongorestore',
@@ -466,6 +476,7 @@ def test_restore_data_source_dump_runs_mongorestore_with_username_and_password()
     flexmock(module).should_receive('make_password_config_file').with_args('trustsome1').and_return(
     flexmock(module).should_receive('make_password_config_file').with_args('trustsome1').and_return(
         '/dev/fd/99',
         '/dev/fd/99',
     )
     )
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         [
         [
             'mongorestore',
             'mongorestore',
@@ -524,6 +535,7 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_
     flexmock(module).should_receive('make_password_config_file').with_args(
     flexmock(module).should_receive('make_password_config_file').with_args(
         'clipassword',
         'clipassword',
     ).and_return('/dev/fd/99')
     ).and_return('/dev/fd/99')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         [
         [
             'mongorestore',
             'mongorestore',
@@ -586,6 +598,7 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_
     flexmock(module).should_receive('make_password_config_file').with_args(
     flexmock(module).should_receive('make_password_config_file').with_args(
         'restorepass',
         'restorepass',
     ).and_return('/dev/fd/99')
     ).and_return('/dev/fd/99')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         [
         [
             'mongorestore',
             'mongorestore',
@@ -633,6 +646,7 @@ def test_restore_data_source_dump_runs_mongorestore_with_options():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ['mongorestore', '--archive', '--drop', '--harder'],
         ['mongorestore', '--archive', '--drop', '--harder'],
         processes=[extract_process],
         processes=[extract_process],
@@ -666,6 +680,7 @@ def test_restore_databases_dump_runs_mongorestore_with_schemas():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         [
         [
             'mongorestore',
             'mongorestore',
@@ -707,6 +722,7 @@ def test_restore_data_source_dump_runs_psql_for_all_database_dump():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ['mongorestore', '--archive'],
         ['mongorestore', '--archive'],
         processes=[extract_process],
         processes=[extract_process],
@@ -765,6 +781,7 @@ def test_restore_data_source_dump_without_extract_process_restores_from_disk():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ['mongorestore', '--dir', '/dump/path', '--drop'],
         ['mongorestore', '--dir', '/dump/path', '--drop'],
         processes=[],
         processes=[],
@@ -800,6 +817,7 @@ def test_dump_data_sources_uses_custom_mongodump_command():
         'databases/localhost/foo',
         'databases/localhost/foo',
     )
     )
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -871,6 +889,7 @@ def test_restore_data_source_dump_uses_custom_mongorestore_command():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         [
         [
             'custom_mongorestore',  # Should use custom command instead of default
             'custom_mongorestore',  # Should use custom command instead of default

+ 26 - 0
tests/unit/hooks/data_source/test_mysql.py

@@ -68,6 +68,7 @@ def test_database_names_to_dump_queries_mysql_for_database_names():
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -108,6 +109,7 @@ def test_database_names_to_dump_with_database_name_all_and_skip_names_filters_ou
         'trustsome1',
         'trustsome1',
         None,
         None,
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -144,6 +146,7 @@ def test_database_names_to_dump_with_environment_password_transport_skips_defaul
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).never()
     ).never()
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -181,6 +184,7 @@ def test_database_names_to_dump_runs_mysql_with_tls():
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -218,6 +222,7 @@ def test_database_names_to_dump_runs_mysql_without_tls():
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -589,6 +594,7 @@ def test_database_names_to_dump_runs_mysql_with_list_options():
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', 'my.cnf').and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', 'my.cnf').and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -621,6 +627,7 @@ def test_database_names_to_dump_runs_non_default_mysql_with_list_options():
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
     flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', 'my.cnf').and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', 'my.cnf').and_return(('--defaults-extra-file=/dev/fd/99',))
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         environment=None,
         environment=None,
         full_command=(
         full_command=(
@@ -655,6 +662,7 @@ def test_execute_dump_command_runs_mysqldump():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -701,6 +709,7 @@ def test_execute_dump_command_with_environment_password_transport_skips_defaults
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).never()
     ).never()
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -748,6 +757,7 @@ def test_execute_dump_command_runs_mysqldump_without_add_drop_database():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -793,6 +803,7 @@ def test_execute_dump_command_runs_mysqldump_with_hostname_and_port():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -845,6 +856,7 @@ def test_execute_dump_command_runs_mysqldump_with_tls():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -892,6 +904,7 @@ def test_execute_dump_command_runs_mysqldump_without_tls():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -939,6 +952,7 @@ def test_execute_dump_command_runs_mysqldump_with_username_and_password():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -985,6 +999,7 @@ def test_execute_dump_command_runs_mysqldump_with_options():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -1032,6 +1047,7 @@ def test_execute_dump_command_runs_non_default_mysqldump():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -1141,6 +1157,7 @@ def test_restore_data_source_dump_runs_mysql_to_restore():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args(None, None, None).and_return(())
     ).with_args(None, None, None).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mysql', '--batch'),
         ('mysql', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1180,6 +1197,7 @@ def test_restore_data_source_dump_runs_mysql_with_options():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args(None, None, None).and_return(())
     ).with_args(None, None, None).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mysql', '--harder', '--batch'),
         ('mysql', '--harder', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1219,6 +1237,7 @@ def test_restore_data_source_dump_runs_non_default_mysql_with_options():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args(None, None, None).and_return(())
     ).with_args(None, None, None).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('custom_mysql', '--harder', '--batch'),
         ('custom_mysql', '--harder', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1258,6 +1277,7 @@ def test_restore_data_source_dump_runs_mysql_with_hostname_and_port():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args(None, None, None).and_return(())
     ).with_args(None, None, None).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -1306,6 +1326,7 @@ def test_restore_data_source_dump_runs_mysql_with_tls():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args(None, None, None).and_return(())
     ).with_args(None, None, None).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -1349,6 +1370,7 @@ def test_restore_data_source_dump_runs_mysql_without_tls():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args(None, None, None).and_return(())
     ).with_args(None, None, None).and_return(())
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -1392,6 +1414,7 @@ def test_restore_data_source_dump_runs_mysql_with_username_and_password():
         'make_defaults_file_options',
         'make_defaults_file_options',
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mysql', '--defaults-extra-file=/dev/fd/99', '--batch'),
         ('mysql', '--defaults-extra-file=/dev/fd/99', '--batch'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1440,6 +1463,7 @@ def test_restore_data_source_with_environment_password_transport_skips_defaults_
     flexmock(module.os).should_receive('environ').and_return(
     flexmock(module.os).should_receive('environ').and_return(
         {'USER': 'root', 'MYSQL_PWD': 'trustsome1'},
         {'USER': 'root', 'MYSQL_PWD': 'trustsome1'},
     )
     )
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('mysql', '--batch', '--user', 'root'),
         ('mysql', '--batch', '--user', 'root'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1491,6 +1515,7 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_
         ('--defaults-extra-file=/dev/fd/99',),
         ('--defaults-extra-file=/dev/fd/99',),
     )
     )
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mysql',
             'mysql',
@@ -1556,6 +1581,7 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_
         ('--defaults-extra-file=/dev/fd/99',),
         ('--defaults-extra-file=/dev/fd/99',),
     )
     )
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
     flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'mysql',
             'mysql',

+ 28 - 1
tests/unit/hooks/data_source/test_postgresql.py

@@ -117,6 +117,9 @@ def test_database_names_to_dump_with_all_and_format_lists_databases_with_hostnam
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
+        '/path/to/working/dir'
+    )
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'psql',
             'psql',
@@ -131,7 +134,7 @@ def test_database_names_to_dump_with_all_and_format_lists_databases_with_hostnam
             '1234',
             '1234',
         ),
         ),
         environment=object,
         environment=object,
-        working_directory=None,
+        working_directory='/path/to/working/dir',
     ).and_return('foo,test,\nbar,test,"stuff and such"')
     ).and_return('foo,test,\nbar,test,"stuff and such"')
 
 
     assert module.database_names_to_dump(database, {}, flexmock(), dry_run=False) == (
     assert module.database_names_to_dump(database, {}, flexmock(), dry_run=False) == (
@@ -145,6 +148,7 @@ def test_database_names_to_dump_with_all_and_format_lists_databases_with_usernam
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'psql',
             'psql',
@@ -171,6 +175,7 @@ def test_database_names_to_dump_with_all_and_format_lists_databases_with_options
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         ('psql', '--list', '--no-password', '--no-psqlrc', '--csv', '--tuples-only', '--harder'),
         ('psql', '--list', '--no-password', '--no-psqlrc', '--csv', '--tuples-only', '--harder'),
         environment=object,
         environment=object,
@@ -204,6 +209,7 @@ def test_database_names_to_dump_with_all_and_psql_command_uses_custom_command():
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
     flexmock(module.borgmatic.hooks.credential.parse).should_receive(
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
     flexmock(module).should_receive('execute_command_and_capture_output').with_args(
         (
         (
             'docker',
             'docker',
@@ -259,6 +265,7 @@ def test_dump_data_sources_runs_pg_dump_for_each_database():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     for name, process in zip(('foo', 'bar'), processes):
     for name, process in zip(('foo', 'bar'), processes):
         flexmock(module).should_receive('execute_command').with_args(
         flexmock(module).should_receive('execute_command').with_args(
@@ -433,6 +440,7 @@ def test_dump_data_sources_runs_pg_dump_with_hostname_and_port():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -498,6 +506,7 @@ def test_dump_data_sources_runs_pg_dump_with_username_and_password():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -559,6 +568,7 @@ def test_dump_data_sources_with_username_injection_attack_gets_escaped():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -618,6 +628,7 @@ def test_dump_data_sources_runs_pg_dump_with_directory_format():
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_parent_directory_for_dump')
     flexmock(module.dump).should_receive('create_parent_directory_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
     flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -677,6 +688,7 @@ def test_dump_data_sources_runs_pg_dump_with_string_compression():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -739,6 +751,7 @@ def test_dump_data_sources_runs_pg_dump_with_integer_compression():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -801,6 +814,7 @@ def test_dump_data_sources_runs_pg_dump_with_options():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -859,6 +873,7 @@ def test_dump_data_sources_runs_pg_dumpall_for_all_databases():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         ('pg_dumpall', '--no-password', '--clean', '--if-exists', '>', 'databases/localhost/all'),
         ('pg_dumpall', '--no-password', '--clean', '--if-exists', '>', 'databases/localhost/all'),
@@ -906,6 +921,7 @@ def test_dump_data_sources_runs_non_default_pg_dump():
         'resolve_credential',
         'resolve_credential',
     ).replace_with(lambda value, config: value)
     ).replace_with(lambda value, config: value)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
 
 
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
@@ -961,6 +977,7 @@ def test_restore_data_source_dump_runs_pg_restore():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',
@@ -1020,6 +1037,7 @@ def test_restore_data_source_dump_runs_pg_restore_with_hostname_and_port():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',
@@ -1089,6 +1107,7 @@ def test_restore_data_source_dump_runs_pg_restore_with_username_and_password():
     )
     )
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',
@@ -1165,6 +1184,7 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_
     )
     )
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',
@@ -1249,6 +1269,7 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_
     )
     )
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',
@@ -1325,6 +1346,7 @@ def test_restore_data_source_dump_runs_pg_restore_with_options():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',
@@ -1384,6 +1406,7 @@ def test_restore_data_source_dump_runs_psql_for_all_database_dump():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'psql',
             'psql',
@@ -1428,6 +1451,7 @@ def test_restore_data_source_dump_runs_psql_for_plain_database_dump():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         ('psql', '--no-password', '--no-psqlrc', '--dbname', 'foo'),
         ('psql', '--no-password', '--no-psqlrc', '--dbname', 'foo'),
         processes=[extract_process],
         processes=[extract_process],
@@ -1484,6 +1508,7 @@ def test_restore_data_source_dump_runs_non_default_pg_restore_and_psql():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
     flexmock(module.dump).should_receive('make_data_source_dump_filename')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'docker',
             'docker',
@@ -1577,6 +1602,7 @@ def test_restore_data_source_dump_without_extract_process_restores_from_disk():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('/dump/path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('/dump/path')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',
@@ -1634,6 +1660,7 @@ def test_restore_data_source_dump_with_schemas_restores_schemas():
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_environment').and_return({'PGSSLMODE': 'disable'})
     flexmock(module).should_receive('make_dump_path')
     flexmock(module).should_receive('make_dump_path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('/dump/path')
     flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('/dump/path')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'pg_restore',
             'pg_restore',

+ 10 - 1
tests/unit/hooks/data_source/test_sqlite.py

@@ -111,6 +111,9 @@ def test_dump_data_sources_with_path_injection_attack_gets_escaped():
     )
     )
     flexmock(module.os.path).should_receive('exists').and_return(False)
     flexmock(module.os.path).should_receive('exists').and_return(False)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
+        '/path/to/working/dir'
+    )
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
             'sqlite3',
             'sqlite3',
@@ -122,7 +125,7 @@ def test_dump_data_sources_with_path_injection_attack_gets_escaped():
         ),
         ),
         shell=True,
         shell=True,
         run_to_completion=False,
         run_to_completion=False,
-        working_directory=None,
+        working_directory='/path/to/working/dir',
     ).and_return(processes[0])
     ).and_return(processes[0])
     flexmock(module.dump).should_receive('write_data_source_dumps_metadata').with_args(
     flexmock(module.dump).should_receive('write_data_source_dumps_metadata').with_args(
         '/run/borgmatic',
         '/run/borgmatic',
@@ -168,6 +171,7 @@ def test_dump_data_sources_runs_non_default_sqlite_with_path_injection_attack_ge
     )
     )
     flexmock(module.os.path).should_receive('exists').and_return(False)
     flexmock(module.os.path).should_receive('exists').and_return(False)
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
     flexmock(module.dump).should_receive('create_named_pipe_for_dump')
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command').with_args(
     flexmock(module).should_receive('execute_command').with_args(
         (
         (
             'custom_sqlite',  # custom sqlite command
             'custom_sqlite',  # custom sqlite command
@@ -326,6 +330,7 @@ def test_restore_data_source_dump_restores_database():
     hook_config = [{'path': '/path/to/database', 'name': 'database'}, {'name': 'other'}]
     hook_config = [{'path': '/path/to/database', 'name': 'database'}, {'name': 'other'}]
     extract_process = flexmock(stdout=flexmock())
     extract_process = flexmock(stdout=flexmock())
 
 
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'sqlite3',
             'sqlite3',
@@ -362,6 +367,7 @@ def test_restore_data_source_dump_runs_non_default_sqlite_restores_database():
     ]
     ]
     extract_process = flexmock(stdout=flexmock())
     extract_process = flexmock(stdout=flexmock())
 
 
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'custom_sqlite',
             'custom_sqlite',
@@ -398,6 +404,7 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_
     ]
     ]
     extract_process = flexmock(stdout=flexmock())
     extract_process = flexmock(stdout=flexmock())
 
 
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'sqlite3',
             'sqlite3',
@@ -433,6 +440,7 @@ def test_restore_data_source_dump_runs_non_default_sqlite_with_connection_params
     ]
     ]
     extract_process = flexmock(stdout=flexmock())
     extract_process = flexmock(stdout=flexmock())
 
 
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'custom_sqlite',
             'custom_sqlite',
@@ -507,6 +515,7 @@ def test_restore_data_source_dump_runs_non_default_sqlite_without_connection_par
     ]
     ]
     extract_process = flexmock(stdout=flexmock())
     extract_process = flexmock(stdout=flexmock())
 
 
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
     flexmock(module).should_receive('execute_command_with_processes').with_args(
     flexmock(module).should_receive('execute_command_with_processes').with_args(
         (
         (
             'custom_sqlite',
             'custom_sqlite',