Răsfoiți Sursa

Add a basic end-to-end test for patterns (#962).

Dan Helfman 4 luni în urmă
părinte
comite
c702a988bd
2 a modificat fișierele cu 51 adăugiri și 8 ștergeri
  1. 9 3
      scripts/run-end-to-end-tests
  2. 42 5
      tests/end-to-end/test_borgmatic.py

+ 9 - 3
scripts/run-end-to-end-tests

@@ -16,7 +16,13 @@ if [ -e "$USER_PODMAN_SOCKET_PATH" ]; then
     export DOCKER_HOST="unix://$USER_PODMAN_SOCKET_PATH"
 fi
 
-docker-compose --file tests/end-to-end/docker-compose.yaml --progress quiet up --force-recreate \
+if [ "`tty`" == "not a tty" ]; then
+    export PROGRESS=quiet
+else
+    export PROGRESS=auto
+fi
+
+docker-compose --file tests/end-to-end/docker-compose.yaml --progress "$PROGRESS" up --force-recreate \
     --renew-anon-volumes --detach
-docker-compose --file tests/end-to-end/docker-compose.yaml --progress quiet attach tests
-docker-compose --file tests/end-to-end/docker-compose.yaml --progress quiet down
+docker-compose --file tests/end-to-end/docker-compose.yaml --progress "$PROGRESS" attach tests
+docker-compose --file tests/end-to-end/docker-compose.yaml --progress "$PROGRESS" down

+ 42 - 5
tests/end-to-end/test_borgmatic.py

@@ -5,12 +5,14 @@ import subprocess
 import sys
 import tempfile
 
+import pytest
 
-def generate_configuration(config_path, repository_path):
+
+def generate_configuration_with_source_directories(config_path, repository_path):
     '''
     Generate borgmatic configuration into a file at the config path, and update the defaults so as
-    to work for testing (including injecting the given repository path and tacking on an encryption
-    passphrase).
+    to work for testing, including updating the source directories, injecting the given repository
+    path, and tacking on an encryption passphrase.
     '''
     subprocess.check_call(f'borgmatic config generate --destination {config_path}'.split(' '))
     config = (
@@ -19,17 +21,52 @@ def generate_configuration(config_path, repository_path):
         .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path)
         .replace('- path: /mnt/backup', '')
         .replace('label: local', '')
+        .replace('- /home/user/path with spaces', '')
         .replace('- /home', f'- {config_path}')
         .replace('- /etc', '')
         .replace('- /var/log/syslog*', '')
-        + 'encryption_passphrase: "test"'
+        + '\nencryption_passphrase: "test"'
+        # Disable automatic storage of config files so we can test storage and extraction manually.
+        + '\nbootstrap:\n  store_config_files: false'
+    )
+    config_file = open(config_path, 'w')
+    config_file.write(config)
+    config_file.close()
+
+
+def generate_configuration_with_patterns(config_path, repository_path):
+    '''
+    Generate borgmatic configuration into a file at the config path, and update the defaults so as
+    to work for testing, including adding patterns, injecting the given repository path, and tacking
+    on an encryption passphrase.
+    '''
+    subprocess.check_call(f'borgmatic config generate --destination {config_path}'.split(' '))
+    config = (
+        open(config_path)
+        .read()
+        .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path)
+        .replace('- path: /mnt/backup', '')
+        .replace('label: local', '')
+        .replace('source_directories:', '')
+        .replace('- /home/user/path with spaces', '')
+        .replace('- /home', '')
+        .replace('- /etc', '')
+        .replace('- /var/log/syslog*', '')
+        + f'\npatterns: ["R {config_path}"]'
+        + '\nencryption_passphrase: "test"'
+        # Disable automatic storage of config files so we can test storage and extraction manually.
+        + '\nbootstrap:\n  store_config_files: false'
     )
     config_file = open(config_path, 'w')
     config_file.write(config)
     config_file.close()
 
 
-def test_borgmatic_command():
+@pytest.mark.parametrize(
+    'generate_configuration',
+    (generate_configuration_with_source_directories, generate_configuration_with_patterns),
+)
+def test_borgmatic_command(generate_configuration):
     # Create a Borg repository.
     temporary_directory = tempfile.mkdtemp()
     repository_path = os.path.join(temporary_directory, 'test.borg')