Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Tests for Borg #1716

Merged
merged 75 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
23ccbde
Initial nox configuration file
jetchirag May 20, 2023
70a9db9
Formatting
jetchirag May 20, 2023
2a46274
Added several tests for test_archives
jetchirag May 24, 2023
6cd2658
added more tests to archives tests
jetchirag May 28, 2023
077f993
Archive more supported file types
jetchirag May 28, 2023
5b3b6c6
Revert "Archive more supported file types"
jetchirag May 28, 2023
e243f68
Archive more supported file types
jetchirag May 28, 2023
14cab4a
Added test for creating / adding repo
jetchirag Jun 1, 2023
05ecaf2
Push changes for conftest.py
jetchirag Jun 1, 2023
0ca5613
Added tests for borg info
jetchirag Jun 6, 2023
c6418e8
Test configuration improvements and bug fixes
jetchirag Jun 8, 2023
a68cb65
conftest.py cleanup
jetchirag Jun 8, 2023
e456f10
Test for creating new archive
jetchirag Jun 9, 2023
6c769e8
Merge branch 'master' into borg-live-tests
jetchirag Jun 9, 2023
854ee60
Fixed prune test
jetchirag Jun 9, 2023
72215dc
Group common fixtures of conftest.py
jetchirag Jun 9, 2023
ce94213
Added nox to dev requirements and adjusted Makefile for nox and unit/…
jetchirag Jun 9, 2023
9067939
Added docstrings to test_archive.py
jetchirag Jun 9, 2023
d19b834
Added coverage to pytests
jetchirag Jun 9, 2023
bb7c2f6
Added all supported versions to nox
jetchirag Jun 11, 2023
a9c3da3
Changed GH action flow to install all required py versions
jetchirag Jun 11, 2023
7f8d1a3
Completed borg diff testing
jetchirag Jun 14, 2023
56827da
Removed unnecessary code from diff test
jetchirag Jun 14, 2023
3e4a462
Added a min borg version fixture
jetchirag Jun 14, 2023
d12dd08
Added libfuse3-dev to linux requirement for fuse3
jetchirag Jun 14, 2023
725b6b0
Added various compatibility check for platform and borg versions
jetchirag Jun 20, 2023
9a0c1c9
GH CI temp speedup
jetchirag Jun 20, 2023
ce33f9e
Solve borg_json_output not found error on archive rename test
jetchirag Jun 20, 2023
4a6c778
Fixed test_borg_repo_info error with invalid repo path
jetchirag Jun 20, 2023
db5d6bb
Macos does not use tmp for tmpdir, fix
jetchirag Jun 20, 2023
6ecdec4
Require pkgconfig to install borg 1.2.0 and above using pip
jetchirag Jun 20, 2023
da05507
pkg-config -> pkgconfig
jetchirag Jun 20, 2023
a1c7190
tmpdir appends integer to generate unique directory for diff tests ru…
jetchirag Jun 23, 2023
914a35a
Always install pre-commit
jetchirag Jun 23, 2023
79d247e
Install libxxhash-dev for linux
jetchirag Jun 23, 2023
9a19d90
Set PKG_CONFIG_PATH for macos
jetchirag Jun 23, 2023
ec87104
Remove python parameterization from nox
jetchirag Jun 24, 2023
282c119
Trial | Restore nox python parameterization with increased timeout
jetchirag Jun 24, 2023
1bc222a
Borg 2 have compact message case change
jetchirag Jun 24, 2023
83695fd
Added docstrings to tests
jetchirag Jun 24, 2023
ede422c
Added docstrings to tests_2
jetchirag Jun 24, 2023
86da9e9
Added pkg config path to env for macos
jetchirag Jun 24, 2023
b95d245
Macos install macfuse
jetchirag Jun 24, 2023
101c709
Attempt at installing borg via github test
jetchirag Jun 24, 2023
6e1c70c
Nox config to use env specified borg version when set
jetchirag Jun 24, 2023
23ce04c
Skip borg mount test on macos (atleast for now)
jetchirag Jun 24, 2023
cd77362
Merge branch 'master' into borg-live-tests
jetchirag Jun 24, 2023
1db9d4b
Cleanup | remove main.show() statements
jetchirag Jun 24, 2023
cf0dfaa
Run unit test seperately
jetchirag Jun 25, 2023
770ecbf
Unit job as include
jetchirag Jun 25, 2023
71f1ef6
Revert unit test config
jetchirag Jun 25, 2023
cd02371
Revert "Revert unit test config"
jetchirag Jun 25, 2023
1e484f1
Revert "Unit job as include"
jetchirag Jun 25, 2023
ba61d9e
Revert "Run unit test seperately"
jetchirag Jun 25, 2023
94bdc97
Merge remote-tracking branch 'upstream/master' into borg-live-tests
jetchirag Jun 25, 2023
26772e5
Restore unit test job
jetchirag Jun 25, 2023
2c51435
New composite action for installation
jetchirag Jun 25, 2023
1b33e37
Composite action require shell property
jetchirag Jun 25, 2023
48afd4b
Unit tests as another job
jetchirag Jun 25, 2023
f1302f4
Fixed breaking of some tests due to introduction of repo name
jetchirag Jun 25, 2023
c0ca616
Minor bug fix, incorrect variable used in asssertion
jetchirag Jun 25, 2023
211dec1
Use llfuse for borg 1.1.18, minor GH action changes
jetchirag Jun 27, 2023
4152103
Debug mount error
jetchirag Jun 27, 2023
55c8a84
Debug mount error 2
jetchirag Jun 27, 2023
99a3c11
raise exception if not mounted
jetchirag Jun 27, 2023
f64d7d3
Revert exception
jetchirag Jun 27, 2023
c8757f2
Minor changes; removed a comment
jetchirag Jul 19, 2023
0cdb4f8
Minor changes; removed a comment
jetchirag Jul 19, 2023
14ce5d4
Merge branch 'master' into borg-live-tests
jetchirag Jul 19, 2023
956eebd
Check for chrdev support
jetchirag Jul 24, 2023
8cc3bc7
Merge branch 'borg-live-tests' of github.com:jetchirag/vorta into bor…
jetchirag Jul 24, 2023
37f91ea
Update to Borg 2.0.0b6
jetchirag Jul 24, 2023
ff0f32a
Merge remote-tracking branch 'upstream/master' into borg-live-tests
jetchirag Aug 3, 2023
1b2f272
Merge Master
jetchirag Aug 3, 2023
0532cd9
Switch to new password widget for test_init
jetchirag Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions noxfile.py
real-yfprojects marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import re

import nox


@nox.session
# @nox.parametrize("borgbackup", ["2.0.0b5", "2.0.0b4"])
@nox.parametrize("borgbackup", ["1.2.4"])
def run_tests(session, borgbackup):
# install borgbackup
session.install(f"borgbackup=={borgbackup}")

# install dependencies
session.install("-r", "requirements.d/dev.txt")
session.install("-e", ".")

# check versions
cli_version = session.run("borg", "--version", silent=True).strip()
cli_version = re.search(r"borg (\S+)", cli_version).group(1)
python_version = session.run("python", "-c", "import borg; print(borg.__version__)", silent=True).strip()

session.log(f"CLI version: {cli_version}")
session.log(f"Python version: {python_version}")

assert cli_version == borgbackup
assert python_version == borgbackup

# run tests
session.run("pytest", *session.posargs)
jetchirag marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
213 changes: 213 additions & 0 deletions tests/integration/conftest.py
real-yfprojects marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
import atexit
import os
import shutil
import subprocess
import sys

import pytest
import vorta
import vorta.application
import vorta.borg.jobs_manager
from peewee import SqliteDatabase
from vorta.store.models import (
ArchiveModel,
BackupProfileModel,
EventLogModel,
RepoModel,
RepoPassword,
SchemaVersion,
SettingsModel,
SourceFileModel,
WifiSettingModel,
)
from vorta.views.main_window import MainWindow

models = [
RepoModel,
RepoPassword,
BackupProfileModel,
SourceFileModel,
SettingsModel,
ArchiveModel,
WifiSettingModel,
EventLogModel,
SchemaVersion,
]


def pytest_configure(config):
sys._called_from_test = True
pytest._wait_defaults = {'timeout': 20000}
os.environ['LANG'] = 'en' # Ensure we test an English UI


@pytest.fixture(scope='session')
def qapp(tmpdir_factory):
# DB is required to init QApplication. New DB used for every test.
tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite')
mock_db = SqliteDatabase(str(tmp_db))
vorta.store.connection.init_db(mock_db)

# Needs to be disabled before calling VortaApp()
if sys.platform == 'darwin':
cfg = vorta.store.models.SettingsModel.get(key='check_full_disk_access')
cfg.value = False
cfg.save()

from vorta.application import VortaApp

qapp = VortaApp([]) # Only init QApplication once to avoid segfaults while testing.

yield qapp
mock_db.close()
qapp.quit()


@pytest.fixture(scope='function', autouse=True)
def create_test_repo(tmpdir_factory):
temp_dir = tmpdir_factory.mktemp('repo')
repo_path = str(temp_dir)

subprocess.run(['borg', 'init', '--encryption=none', repo_path], check=True)

# create source files dir
source_files_dir = os.path.join(temp_dir, 'src')
os.mkdir(source_files_dir)

# /src/file
file_path = os.path.join(source_files_dir, 'file')
with open(file_path, 'w') as f:
f.write('test')

# /src/dir/
dir_path = os.path.join(source_files_dir, 'dir')
os.mkdir(dir_path)

# /src/dir/file
file_path = os.path.join(dir_path, 'file')
with open(file_path, 'w') as f:
f.write('test')

# Create first archive
subprocess.run(['borg', 'create', f'{repo_path}::test-archive1', source_files_dir], cwd=temp_dir, check=True)

# /src/dir/symlink
symlink_path = os.path.join(dir_path, 'symlink')
os.symlink(file_path, symlink_path)

# /src/dir/hardlink
hardlink_path = os.path.join(dir_path, 'hardlink')
os.link(file_path, hardlink_path)

# /src/dir/fifo
fifo_path = os.path.join(dir_path, 'fifo')
os.mkfifo(fifo_path)

# /src/dir/socket
socket_path = os.path.join(dir_path, 'socket')
os.mknod(socket_path, mode=0o600 | 0o140000)

# /src/dir/chrdev
chrdev_path = os.path.join(dir_path, 'chrdev')
os.mknod(chrdev_path, mode=0o600 | 0o020000)

# /src/dir/blkdev
# blkdev_path = os.path.join(dir_path, 'blkdev')
# os.mknod(blkdev_path, mode=0o600 | 0o060000)
jetchirag marked this conversation as resolved.
Show resolved Hide resolved

subprocess.run(['borg', 'create', f'{repo_path}::test-archive2', source_files_dir], cwd=temp_dir, check=True)

# Rename dir to dir1
os.rename(dir_path, os.path.join(source_files_dir, 'dir1'))

subprocess.run(['borg', 'create', f'{repo_path}::test-archive3', source_files_dir], cwd=temp_dir, check=True)

# Rename all files under dir1
for file in os.listdir(os.path.join(source_files_dir, 'dir1')):
os.rename(os.path.join(source_files_dir, 'dir1', file), os.path.join(source_files_dir, 'dir1', file + '1'))

subprocess.run(['borg', 'create', f'{repo_path}::test-archive4', source_files_dir], cwd=temp_dir, check=True)

# Delete all file under dir1
for file in os.listdir(os.path.join(source_files_dir, 'dir1')):
os.remove(os.path.join(source_files_dir, 'dir1', file))

subprocess.run(['borg', 'create', f'{repo_path}::test-archive5', source_files_dir], cwd=temp_dir, check=True)

def cleanup():
shutil.rmtree(temp_dir)

atexit.register(cleanup)

return repo_path, source_files_dir


@pytest.fixture(scope='function', autouse=True)
def init_db(qapp, qtbot, tmpdir_factory, create_test_repo):
tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite')
mock_db = SqliteDatabase(
str(tmp_db),
pragmas={
'journal_mode': 'wal',
},
)
vorta.store.connection.init_db(mock_db)

default_profile = BackupProfileModel(name='Default')
default_profile.save()

repo_path, source_dir = create_test_repo

new_repo = RepoModel(url=repo_path)
new_repo.encryption = 'none'
new_repo.save()

default_profile.repo = new_repo.id
default_profile.dont_run_on_metered_networks = False
default_profile.validation_on = False
default_profile.save()

source_dir = SourceFileModel(dir=source_dir, repo=new_repo, dir_size=12, dir_files_count=3, path_isdir=True)
source_dir.save()

qapp.main_window.deleteLater()
del qapp.main_window
qapp.main_window = MainWindow(qapp) # Re-open main window to apply mock data in UI

qapp.scheduler.schedule_changed.disconnect()

yield

qapp.jobs_manager.cancel_all_jobs()
qapp.backup_finished_event.disconnect()
qtbot.waitUntil(lambda: not qapp.jobs_manager.is_worker_running(), **pytest._wait_defaults)
mock_db.close()


@pytest.fixture
def choose_file_dialog(tmpdir):
class MockFileDialog:
def __init__(self, *args, **kwargs):
pass

def open(self, func):
func()

def selectedFiles(self):
return [str(tmpdir)]

return MockFileDialog


@pytest.fixture
def borg_json_output():
def _read_json(subcommand):
stdout = open(f'tests/borg_json_output/{subcommand}_stdout.json')
stderr = open(f'tests/borg_json_output/{subcommand}_stderr.json')
return stdout, stderr

return _read_json

@pytest.fixture
def rootdir():
return os.path.dirname(os.path.abspath(__file__))
Loading