Add tests for pass-through of BORG_* environment variables.

This commit is contained in:
Dan Helfman 2020-06-21 14:41:22 -07:00
parent c8d5de2179
commit 17c2d109e5
3 changed files with 18 additions and 4 deletions

1
NEWS
View file

@ -1,4 +1,5 @@
1.5.7.dev0
* #327: Fix broken pass-through of BORG_* environment variables to Borg.
* #331: Add SSL support to PostgreSQL database configuration.
* #333: Fix for potential data loss (data not getting backed up) when borgmatic omitted configured
source directories in certain situations. Specifically, this occurred when two source directories

View file

@ -19,8 +19,11 @@ DEFAULT_BOOL_OPTION_TO_ENVIRONMENT_VARIABLE = {
def initialize(storage_config):
for option_name, environment_variable_name in OPTION_TO_ENVIRONMENT_VARIABLE.items():
# Options from the config.yaml file have precedence over already set env variables:
# Options from borgmatic configuration take precedence over already set BORG_* environment
# variables.
value = storage_config.get(option_name) or os.environ.get(environment_variable_name)
if value:
os.environ[environment_variable_name] = value
else:

View file

@ -62,13 +62,23 @@ def test_initialize_with_relocated_repo_access_should_override_default():
os.environ = orig_environ
def test_initialize_is_not_affected_by_existing_environment():
def test_initialize_prefers_configuration_option_over_borg_environment_variable():
orig_environ = os.environ
try:
os.environ = {'BORG_PASSPHRASE': 'pass', 'BORG_SSH': 'mosh'}
os.environ = {'BORG_SSH': 'mosh'}
module.initialize({'ssh_command': 'ssh -C'})
assert 'BORG_PASSPHRASE' not in os.environ
assert os.environ.get('BORG_RSH') == 'ssh -C'
finally:
os.environ = orig_environ
def test_initialize_passes_through_existing_borg_environment_variable():
orig_environ = os.environ
try:
os.environ = {'BORG_PASSPHRASE': 'pass'}
module.initialize({'ssh_command': 'ssh -C'})
assert os.environ.get('BORG_PASSPHRASE') == 'pass'
finally:
os.environ = orig_environ