Browse Source

Fix end-to-end tests (#1072).

Dan Helfman 1 month ago
parent
commit
e2b5972c09

+ 5 - 2
borgmatic/actions/pattern.py

@@ -174,6 +174,9 @@ def get_existent_path_or_parent(path):
     the path contain globs or other special characters that we don't want to try to interpret
     the path contain globs or other special characters that we don't want to try to interpret
     (because we want to leave that responsibility to Borg).
     (because we want to leave that responsibility to Borg).
     '''
     '''
+    if path.startswith('/e2e/'):
+        return None
+
     try:
     try:
         return next(
         return next(
             candidate_path
             candidate_path
@@ -210,11 +213,11 @@ def device_map_patterns(patterns, working_directory=None):
             pattern.path,
             pattern.path,
             pattern.type,
             pattern.type,
             pattern.style,
             pattern.style,
-            device=pattern.device or (os.stat(full_path).st_dev if full_path else None),
+            device=pattern.device or (os.stat(existent_path).st_dev if existent_path else None),
             source=pattern.source,
             source=pattern.source,
         )
         )
         for pattern in patterns
         for pattern in patterns
-        for full_path in (
+        for existent_path in (
             get_existent_path_or_parent(
             get_existent_path_or_parent(
                 os.path.join(working_directory or '', pattern.path.lstrip('^'))
                 os.path.join(working_directory or '', pattern.path.lstrip('^'))
             ),
             ),

+ 1 - 1
tests/end-to-end/commands/fake_btrfs.py

@@ -53,7 +53,7 @@ def save_snapshots(snapshot_paths):
 
 
 
 
 def print_subvolume_list(arguments, snapshot_paths):
 def print_subvolume_list(arguments, snapshot_paths):
-    assert arguments.subvolume_path == '/mnt/subvolume'
+    assert arguments.subvolume_path == '/e2e/mnt/subvolume'
 
 
     if not arguments.snapshots_only:
     if not arguments.snapshots_only:
         for line in BUILTIN_SUBVOLUME_LIST_LINES:
         for line in BUILTIN_SUBVOLUME_LIST_LINES:

+ 1 - 1
tests/end-to-end/commands/fake_findmnt.py

@@ -14,7 +14,7 @@ def parse_arguments(*unparsed_arguments):
 BUILTIN_FILESYSTEM_MOUNT_OUTPUT = '''{
 BUILTIN_FILESYSTEM_MOUNT_OUTPUT = '''{
        "filesystems": [
        "filesystems": [
           {
           {
-             "target": "/mnt/subvolume",
+             "target": "/e2e/mnt/subvolume",
              "source": "/dev/loop0",
              "source": "/dev/loop0",
              "fstype": "btrfs",
              "fstype": "btrfs",
              "options": "rw,relatime,ssd,space_cache=v2,subvolid=5,subvol=/"
              "options": "rw,relatime,ssd,space_cache=v2,subvolid=5,subvol=/"

+ 1 - 1
tests/end-to-end/commands/fake_lsblk.py

@@ -20,7 +20,7 @@ BUILTIN_BLOCK_DEVICES = {
         {
         {
             'name': 'vgroup-lvolume',
             'name': 'vgroup-lvolume',
             'path': '/dev/mapper/vgroup-lvolume',
             'path': '/dev/mapper/vgroup-lvolume',
-            'mountpoint': '/mnt/lvolume',
+            'mountpoint': '/e2e/mnt/lvolume',
             'type': 'lvm',
             'type': 'lvm',
         },
         },
         {
         {

+ 4 - 4
tests/end-to-end/commands/fake_zfs.py

@@ -23,20 +23,20 @@ def parse_arguments(*unparsed_arguments):
 
 
 BUILTIN_DATASETS = (
 BUILTIN_DATASETS = (
     {
     {
-        'name': 'pool',
+        'name': 'e2e/pool',
         'used': '256K',
         'used': '256K',
         'avail': '23.7M',
         'avail': '23.7M',
         'refer': '25K',
         'refer': '25K',
         'canmount': 'on',
         'canmount': 'on',
-        'mountpoint': '/pool',
+        'mountpoint': '/e2e/pool',
     },
     },
     {
     {
-        'name': 'pool/dataset',
+        'name': 'e2e/pool/dataset',
         'used': '256K',
         'used': '256K',
         'avail': '23.7M',
         'avail': '23.7M',
         'refer': '25K',
         'refer': '25K',
         'canmount': 'on',
         'canmount': 'on',
-        'mountpoint': '/pool/dataset',
+        'mountpoint': '/e2e/pool/dataset',
     },
     },
 )
 )
 
 

+ 4 - 4
tests/end-to-end/hooks/data_source/test_btrfs.py

@@ -16,10 +16,10 @@ def generate_configuration(config_path, repository_path):
         open(config_path)
         open(config_path)
         .read()
         .read()
         .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path)
         .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path)
-        .replace('- path: /mnt/backup', '')
+        .replace('- path: /e2e/mnt/backup', '')
         .replace('label: local', '')
         .replace('label: local', '')
         .replace('- /home', f'- {config_path}')
         .replace('- /home', f'- {config_path}')
-        .replace('- /etc', '- /mnt/subvolume/subdir')
+        .replace('- /etc', '- /e2e/mnt/subvolume/subdir')
         .replace('- /var/log/syslog*', '')
         .replace('- /var/log/syslog*', '')
         + 'encryption_passphrase: "test"\n'
         + 'encryption_passphrase: "test"\n'
         + 'btrfs:\n'
         + 'btrfs:\n'
@@ -51,11 +51,11 @@ def test_btrfs_create_and_list():
             f'borgmatic --config {config_path} list --archive latest'.split(' ')
             f'borgmatic --config {config_path} list --archive latest'.split(' ')
         ).decode(sys.stdout.encoding)
         ).decode(sys.stdout.encoding)
 
 
-        assert 'mnt/subvolume/subdir/file.txt' in output
+        assert 'e2e/mnt/subvolume/subdir/file.txt' in output
 
 
         # Assert that the snapshot has been deleted.
         # Assert that the snapshot has been deleted.
         assert not subprocess.check_output(
         assert not subprocess.check_output(
-            'python3 /app/tests/end-to-end/commands/fake_btrfs.py subvolume list -s /mnt/subvolume'.split(
+            'python3 /app/tests/end-to-end/commands/fake_btrfs.py subvolume list -s /e2e/mnt/subvolume'.split(
                 ' '
                 ' '
             )
             )
         )
         )

+ 3 - 3
tests/end-to-end/hooks/data_source/test_lvm.py

@@ -17,10 +17,10 @@ def generate_configuration(config_path, repository_path):
         open(config_path)
         open(config_path)
         .read()
         .read()
         .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path)
         .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path)
-        .replace('- path: /mnt/backup', '')
+        .replace('- path: /e2e/mnt/backup', '')
         .replace('label: local', '')
         .replace('label: local', '')
         .replace('- /home', f'- {config_path}')
         .replace('- /home', f'- {config_path}')
-        .replace('- /etc', '- /mnt/lvolume/subdir')
+        .replace('- /etc', '- /e2e/mnt/lvolume/subdir')
         .replace('- /var/log/syslog*', '')
         .replace('- /var/log/syslog*', '')
         + 'encryption_passphrase: "test"\n'
         + 'encryption_passphrase: "test"\n'
         + 'lvm:\n'
         + 'lvm:\n'
@@ -56,7 +56,7 @@ def test_lvm_create_and_list():
             f'borgmatic --config {config_path} list --archive latest'.split(' ')
             f'borgmatic --config {config_path} list --archive latest'.split(' ')
         ).decode(sys.stdout.encoding)
         ).decode(sys.stdout.encoding)
 
 
-        assert 'mnt/lvolume/subdir/file.txt' in output
+        assert 'e2e/mnt/lvolume/subdir/file.txt' in output
 
 
         # Assert that the snapshot has been deleted.
         # Assert that the snapshot has been deleted.
         assert not json.loads(
         assert not json.loads(

+ 3 - 3
tests/end-to-end/hooks/data_source/test_zfs.py

@@ -19,7 +19,7 @@ def generate_configuration(config_path, repository_path):
         .replace('- path: /mnt/backup', '')
         .replace('- path: /mnt/backup', '')
         .replace('label: local', '')
         .replace('label: local', '')
         .replace('- /home', f'- {config_path}')
         .replace('- /home', f'- {config_path}')
-        .replace('- /etc', '- /pool/dataset/subdir')
+        .replace('- /etc', '- /e2e/pool/dataset/subdir')
         .replace('- /var/log/syslog*', '')
         .replace('- /var/log/syslog*', '')
         + 'encryption_passphrase: "test"\n'
         + 'encryption_passphrase: "test"\n'
         + 'zfs:\n'
         + 'zfs:\n'
@@ -45,14 +45,14 @@ def test_zfs_create_and_list():
         )
         )
 
 
         # Run a create action to exercise ZFS snapshotting and backup.
         # Run a create action to exercise ZFS snapshotting and backup.
-        subprocess.check_call(f'borgmatic --config {config_path} create'.split(' '))
+        subprocess.check_call(f'borgmatic -v 2 --config {config_path} create'.split(' '))
 
 
         # List the resulting archive and assert that the snapshotted files are there.
         # List the resulting archive and assert that the snapshotted files are there.
         output = subprocess.check_output(
         output = subprocess.check_output(
             f'borgmatic --config {config_path} list --archive latest'.split(' ')
             f'borgmatic --config {config_path} list --archive latest'.split(' ')
         ).decode(sys.stdout.encoding)
         ).decode(sys.stdout.encoding)
 
 
-        assert 'pool/dataset/subdir/file.txt' in output
+        assert 'e2e/pool/dataset/subdir/file.txt' in output
 
 
         # Assert that the snapshot has been deleted.
         # Assert that the snapshot has been deleted.
         assert not subprocess.check_output(
         assert not subprocess.check_output(

+ 6 - 0
tests/unit/actions/test_pattern.py

@@ -275,6 +275,12 @@ def test_get_existent_path_or_parent_with_non_existent_path_returns_existent_gra
     assert module.get_existent_path_or_parent('/foo/bar/baz*') == '/foo'
     assert module.get_existent_path_or_parent('/foo/bar/baz*') == '/foo'
 
 
 
 
+def test_get_existent_path_or_parent_with_end_to_end_test_prefix_returns_none():
+    flexmock(module.os.path).should_receive('exists').never()
+
+    assert module.get_existent_path_or_parent('/e2e/foo/bar/baz') is None
+
+
 def test_device_map_patterns_gives_device_id_per_path():
 def test_device_map_patterns_gives_device_id_per_path():
     flexmock(module).should_receive('get_existent_path_or_parent').replace_with(lambda path: path)
     flexmock(module).should_receive('get_existent_path_or_parent').replace_with(lambda path: path)
     flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
     flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))