Преглед на файлове

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

Dan Helfman преди 5 години
родител
ревизия
17c2d109e5
променени са 3 файла, в които са добавени 18 реда и са изтрити 4 реда
  1. 1 0
      NEWS
  2. 4 1
      borgmatic/borg/environment.py
  3. 13 3
      tests/unit/borg/test_environment.py

+ 1 - 0
NEWS

@@ -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

+ 4 - 1
borgmatic/borg/environment.py

@@ -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:

+ 13 - 3
tests/unit/borg/test_environment.py

@@ -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