1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2025-01-03 13:45:49 +00:00
vorta/tests/integration/test_diff.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

399 lines
13 KiB
Python
Raw Normal View History

"""
These tests compare the output of the diff command with the expected output.
"""
import pytest
2024-10-20 13:04:25 +00:00
from packaging.version import Version
import vorta.borg
import vorta.utils
import vorta.views.archive_tab
from vorta.borg.diff import BorgDiffJob
from vorta.views.diff_result import (
ChangeType,
DiffTree,
FileType,
ParseThread,
)
@pytest.mark.parametrize(
2024-10-18 14:17:34 +00:00
"archive_name_1, archive_name_2, expected",
[
(
2024-10-18 14:17:34 +00:00
"test-archive1",
"test-archive2",
[
{
2024-10-18 14:17:34 +00:00
"subpath": "dir",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.MODIFIED,
"modified": None,
},
2024-10-18 14:17:34 +00:00
"min_version": "1.2.4",
"max_version": "1.4.0",
},
{
2024-10-18 14:17:34 +00:00
"subpath": "file",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.MODIFIED,
"modified": (0, 0),
},
2024-10-18 14:17:34 +00:00
"min_version": "1.2.4",
"max_version": "1.4.0",
},
{
2024-10-18 14:17:34 +00:00
"subpath": "chrdev",
"data": {
"file_type": FileType.CHRDEV,
"change_type": ChangeType.ADDED,
"modified": None,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "fifo",
"data": {
"file_type": FileType.FIFO,
"change_type": ChangeType.ADDED,
"modified": None,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "hardlink",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.ADDED,
"modified": None,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "symlink",
"data": {
"file_type": FileType.LINK,
"change_type": ChangeType.ADDED,
"modified": None,
},
},
],
),
(
2024-10-18 14:17:34 +00:00
"test-archive2",
"test-archive3",
[
{
2024-10-18 14:17:34 +00:00
"subpath": "borg_src",
"match_startsWith": True,
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.MODIFIED,
"modified": None,
},
2024-10-18 14:17:34 +00:00
"min_version": "1.2.4",
"max_version": "1.4.0",
},
{
2024-10-18 14:17:34 +00:00
"subpath": "dir",
"data": {
"file_type": FileType.DIRECTORY,
"change_type": ChangeType.REMOVED,
"modified": None,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "chrdev",
"data": {
"file_type": FileType.CHRDEV,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "fifo",
"data": {
"file_type": FileType.FIFO,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "file",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "hardlink",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "symlink",
"data": {
"file_type": FileType.LINK,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "dir1",
"data": {
"file_type": FileType.DIRECTORY,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "chrdev",
"data": {
"file_type": FileType.CHRDEV,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "fifo",
"data": {
"file_type": FileType.FIFO,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "file",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "hardlink",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "symlink",
"data": {
"file_type": FileType.LINK,
"change_type": ChangeType.ADDED,
},
},
],
),
(
2024-10-18 14:17:34 +00:00
"test-archive3",
"test-archive4",
[
{
2024-10-18 14:17:34 +00:00
"subpath": "dir1",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.MODIFIED,
},
2024-10-18 14:17:34 +00:00
"min_version": "1.2.4",
"max_version": "1.4.0",
},
{
2024-10-18 14:17:34 +00:00
"subpath": "chrdev",
"data": {
"file_type": FileType.CHRDEV,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "chrdev1",
"data": {
"file_type": FileType.CHRDEV,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "fifo",
"data": {
"file_type": FileType.FIFO,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "fifo1",
"data": {
"file_type": FileType.FIFO,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "file",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "file1",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "hardlink",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "hardlink1",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.ADDED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "symlink",
"data": {
"file_type": FileType.LINK,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "symlink1",
"data": {
"file_type": FileType.LINK,
"change_type": ChangeType.ADDED,
},
},
],
),
(
2024-10-18 14:17:34 +00:00
"test-archive4",
"test-archive5",
[
{
2024-10-18 14:17:34 +00:00
"subpath": "dir1",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.MODIFIED,
},
2024-10-18 14:17:34 +00:00
"min_version": "1.2.4",
"max_version": "1.4.0",
},
{
2024-10-18 14:17:34 +00:00
"subpath": "chrdev1",
"data": {
"file_type": FileType.CHRDEV,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "fifo1",
"data": {
"file_type": FileType.FIFO,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "file1",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "hardlink1",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.REMOVED,
},
},
{
2024-10-18 14:17:34 +00:00
"subpath": "symlink1",
"data": {
"file_type": FileType.LINK,
"change_type": ChangeType.REMOVED,
},
},
],
),
(
2024-10-18 14:17:34 +00:00
"test-archive5",
"test-archive6",
[
{
2024-10-18 14:17:34 +00:00
"subpath": "dir1",
"data": {
"file_type": FileType.FILE,
"change_type": ChangeType.MODIFIED,
},
2024-10-18 14:17:34 +00:00
"min_version": "1.2.4",
"max_version": "1.4.0",
},
],
),
],
)
2024-10-18 14:17:34 +00:00
def test_archive_diff_lines(
qapp,
qtbot,
borg_version,
create_test_repo,
archive_name_1,
archive_name_2,
expected,
):
"""Test that the diff lines are parsed correctly for supported borg versions"""
parsed_borg_version = borg_version[1]
2024-10-20 13:04:25 +00:00
supports_fifo = parsed_borg_version > Version("1.1.18")
supports_chrdev = create_test_repo[2]
2024-10-18 14:17:34 +00:00
params = BorgDiffJob.prepare(
vorta.store.models.BackupProfileModel.select().first(),
archive_name_1,
archive_name_2,
)
thread = BorgDiffJob(params["cmd"], params, qapp)
with qtbot.waitSignal(thread.result, **pytest._wait_defaults) as blocker:
blocker.connect(thread.updated)
thread.run()
2024-10-18 14:17:34 +00:00
diff_lines = blocker.args[0]["data"]
json_lines = blocker.args[0]["params"]["json_lines"]
model = DiffTree()
model.setMode(model.DisplayMode.FLAT)
# Use ParseThread to parse the diff lines
parse_thread = ParseThread(diff_lines, json_lines, model)
parse_thread.start()
qtbot.waitUntil(lambda: parse_thread.isFinished(), **pytest._wait_defaults)
expected = [
item
for item in expected
if (
2024-10-20 13:04:25 +00:00
("min_version" not in item or Version(item["min_version"]) <= parsed_borg_version)
and ("max_version" not in item or Version(item["max_version"]) >= parsed_borg_version)
2024-10-18 14:17:34 +00:00
and (item["data"]["file_type"] != FileType.FIFO or supports_fifo)
and (item["data"]["file_type"] != FileType.CHRDEV or supports_chrdev)
)
]
# diff versions of borg produce inconsistent ordering of diff lines so we sort the expected and model
2024-10-18 14:17:34 +00:00
expected = sorted(expected, key=lambda item: item["subpath"])
sorted_model = sorted(
[model.index(index, 0).internalPointer() for index in range(model.rowCount())],
key=lambda item: item.subpath,
)
assert len(sorted_model) == len(expected)
for index, item in enumerate(expected):
2024-10-18 14:17:34 +00:00
if "match_startsWith" in item and item["match_startsWith"]:
assert sorted_model[index].subpath.startswith(item["subpath"])
else:
2024-10-18 14:17:34 +00:00
assert sorted_model[index].subpath == item["subpath"]
2024-10-18 14:17:34 +00:00
for key, value in item["data"].items():
assert getattr(sorted_model[index].data, key) == value