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

This commit is contained in:
2025-01-15 10:33:38 -08:00
parent 5560f30aa6
commit c702a988bd
2 changed files with 51 additions and 8 deletions

View File

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

View File

@@ -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 test_borgmatic_command():
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()
@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')