Selaa lähdekoodia

Make end-to-end test clean up after itself, and drop unnecessary use of Docker for it.

Dan Helfman 6 vuotta sitten
vanhempi
sitoutus
3ce5533103
4 muutettua tiedostoa jossa 40 lisäystä ja 30 poistoa
  1. 2 0
      .drone.yml
  2. 2 5
      README.md
  3. 34 20
      tests/end-to-end/test_borgmatic.py
  4. 2 5
      tox.ini

+ 2 - 0
.drone.yml

@@ -5,3 +5,5 @@ pipeline:
     commands:
       - pip install tox
       - tox
+      - apk add --no-cache borgbackup
+      - tox -e end-to-end

+ 2 - 5
README.md

@@ -457,16 +457,13 @@ tox -e black
 
 borgmatic additionally includes some end-to-end tests that integration test
 with Borg for a few representative scenarios. These tests don't run by default
-because they're slow and require Docker. If you would like to run them, first
-install Docker, and make sure that it's executable by the current user. Then:
+because they're relatively slow and depend on Borg. If you would like to run
+them:
 
 ```bash
 tox -e end-to-end
 ```
 
-That builds a test container with your local borgmatic source, and runs
-end-to-end tests within it.
-
 ## Troubleshooting
 
 ### Broken pipe with remote repository

+ 34 - 20
tests/end-to-end/test_borgmatic.py

@@ -1,39 +1,53 @@
 import json
 import os
+import shutil
 import subprocess
 import sys
+import tempfile
 
 
-def generate_configuration():
-    subprocess.check_call('generate-borgmatic-config --destination test.yaml'.split(' '))
+def generate_configuration(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).
+    '''
+    subprocess.check_call(f'generate-borgmatic-config --destination {config_path}'.split(' '))
     config = (
-        open('test.yaml')
+        open(config_path)
         .read()
-        .replace('user@backupserver:sourcehostname.borg', 'test.borg')
-        .replace('- /etc', '- /app')
+        .replace('user@backupserver:sourcehostname.borg', repository_path)
+        .replace('- /home', f'- {config_path}')
+        .replace('- /etc', '')
         .replace('- /var/log/syslog*', '')
     )
-    config_file = open('test.yaml', 'w')
+    config_file = open(config_path, 'w')
     config_file.write(config)
     config_file.close()
 
 
 def test_borgmatic_command():
     # Create a Borg repository.
-    subprocess.check_call(
-        'borg init --encryption repokey test.borg'.split(' '),
-        env={'BORG_PASSPHRASE': '', **os.environ},
-    )
+    temporary_directory = tempfile.mkdtemp()
+    repository_path = os.path.join(temporary_directory, 'test.borg')
 
-    # Generate borgmatic configuration, and update the defaults so as to work for this test.
-    generate_configuration()
+    try:
+        subprocess.check_call(
+            f'borg init --encryption repokey {repository_path}'.split(' '),
+            env={'BORG_PASSPHRASE': '', **os.environ},
+        )
 
-    # Run borgmatic to generate a backup archive, and then list it to make sure it exists.
-    subprocess.check_call('borgmatic --config test.yaml'.split(' '))
-    output = subprocess.check_output(
-        'borgmatic --config test.yaml --list --json'.split(' '), encoding=sys.stdout.encoding
-    )
-    parsed_output = json.loads(output)
+        config_path = os.path.join(temporary_directory, 'test.yaml')
+        generate_configuration(config_path, repository_path)
+
+        # Run borgmatic to generate a backup archive, and then list it to make sure it exists.
+        subprocess.check_call(f'borgmatic --config {config_path}'.split(' '))
+        output = subprocess.check_output(
+            f'borgmatic --config {config_path} --list --json'.split(' '),
+            encoding=sys.stdout.encoding,
+        )
+        parsed_output = json.loads(output)
 
-    assert len(parsed_output) == 1
-    assert len(parsed_output[0]['archives']) == 1
+        assert len(parsed_output) == 1
+        assert len(parsed_output[0]['archives']) == 1
+    finally:
+        shutil.rmtree(temporary_directory)

+ 2 - 5
tox.ini

@@ -17,12 +17,9 @@ commands =
     black --skip-string-normalization --line-length 100 .
 
 [testenv:end-to-end]
-whitelist_externals = docker
-skip_install = true
-deps =
+deps = -rtest_requirements.txt
 commands =
-    docker build --file tests/end-to-end/Dockerfile --tag borgmatic-test .
-    docker run --rm borgmatic-test py.test tests/end-to-end []
+    py.test tests/end-to-end []
 
 [flake8]
 ignore = E501,W503