Skip to content

Commit

Permalink
Add test to make sure 0-added,0-removed modified changes aren't in JS…
Browse files Browse the repository at this point in the history
…ON output.
  • Loading branch information
cr1901 committed Aug 16, 2024
1 parent 6e9857b commit 3b3e2bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/borg/testsuite/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from hashlib import sha256
from io import BytesIO, StringIO
from unittest.mock import patch
from pathlib import Path

import pytest

Expand Down Expand Up @@ -4472,6 +4473,7 @@ def test_basic_functionality(self):
self.create_regular_file('file_removed', size=256)
self.create_regular_file('file_removed2', size=512)
self.create_regular_file('file_replaced', size=1024)
self.create_regular_file('file_touched', size=128)
os.mkdir('input/dir_replaced_with_file')
os.chmod('input/dir_replaced_with_file', stat.S_IFDIR | 0o755)
os.mkdir('input/dir_removed')
Expand Down Expand Up @@ -4500,6 +4502,7 @@ def test_basic_functionality(self):
self.create_regular_file('file_replaced', contents=b'0' * 4096)
os.unlink('input/file_removed')
os.unlink('input/file_removed2')
Path('input/file_touched').touch()
os.rmdir('input/dir_replaced_with_file')
self.create_regular_file('dir_replaced_with_file', size=8192)
os.chmod('input/dir_replaced_with_file', stat.S_IFREG | 0o755)
Expand Down Expand Up @@ -4562,6 +4565,13 @@ def do_asserts(output, can_compare_ids, content_only=False):
change = '0 B' if can_compare_ids else '{:<19}'.format('modified')
self.assert_line_exists(lines, f"{change}.*input/empty")

# Show a 0 byte change for a file whose contents weren't modified
# for text output.
if content_only:
assert "input/file_touched" not in output
else:
self.assert_line_exists(lines, f"{change}.*input/file_touched")

if are_hardlinks_supported():
self.assert_line_exists(lines, f"{change}.*input/hardlink_contents_changed")
if are_symlinks_supported():
Expand Down Expand Up @@ -4610,6 +4620,16 @@ def get_changes(filename, data):
# File unchanged
assert not any(get_changes('input/file_unchanged', joutput))

# Do NOT show a 0 byte change for a file whose contents weren't
# modified for JSON output.
unexpected = {'type': 'modified', 'added': 0, 'removed': 0}
assert unexpected not in get_changes('input/file_touched', joutput)
if not content_only:
assert {"ctime", "mtime"}.issubset({c["type"] for c in get_changes('input/file_touched', joutput)})
else:
# And if we're doing content-only, don't show the file at all.
assert not any(get_changes('input/file_touched', joutput))

# Directory replaced with a regular file
if 'BORG_TESTS_IGNORE_MODES' not in os.environ and not content_only:
assert {'type': 'mode', 'old_mode': 'drwxr-xr-x', 'new_mode': '-rwxr-xr-x'} in \
Expand Down
13 changes: 11 additions & 2 deletions src/borg/testsuite/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pytest
from packaging.version import parse as parse_version, Version

# IMPORTANT keep this above all other borg imports to avoid inconsistent values
# for `from borg.constants import PBKDF2_ITERATIONS` (or star import) usages before
Expand Down Expand Up @@ -37,8 +38,7 @@ def clean_env(tmpdir_factory, monkeypatch):
for key in keys:
monkeypatch.delenv(key, raising=False)


def pytest_report_header(config, start_path):
def _pytest_report_header(config, start_path):
tests = {
"BSD flags": has_lchflags,
"fuse2": has_llfuse,
Expand All @@ -60,6 +60,15 @@ def pytest_report_header(config, start_path):
output += "Tests disabled: " + ", ".join(disabled)
return output

# Avoid "Argument(s) {'start_path'} are declared in the hookimpl but can not
# be found in the hookspec" for pytest 6.2.x.
if parse_version(pytest.__version__) < Version("7.0.0"):
def pytest_report_header(config):
_pytest_report_header(config, None)
else:
def pytest_report_header(config, start_path):
_pytest_report_header(config, start_path)


class DefaultPatches:
def __init__(self, request):
Expand Down

0 comments on commit 3b3e2bb

Please sign in to comment.