Add tests for mount
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import argparse
|
||||
from unittest import mock
|
||||
import pytest
|
||||
import subprocess
|
||||
|
||||
from locutus.mount import run_mount
|
||||
|
||||
@@ -161,3 +162,39 @@ def test_mount_usage_message(capsys):
|
||||
assert rc == 1
|
||||
err = capsys.readouterr().err
|
||||
assert 'Usage:' in err
|
||||
|
||||
|
||||
@mock.patch("locutus.mount.LocutusConfig")
|
||||
@mock.patch("os.path.isdir", return_value=True)
|
||||
@mock.patch("subprocess.run")
|
||||
def test_mount_calledprocesserror_on_mount(mock_run, mock_isdir, mock_config, tmp_path, capsys):
|
||||
mock_config.return_value.get_repo.return_value = "/repo"
|
||||
mock_config.return_value.env = {}
|
||||
archives = ["a", "b", "c"]
|
||||
mock_run.side_effect = [
|
||||
mock.Mock(stdout="\n".join(archives) + "\n", returncode=0), # listing works
|
||||
subprocess.CalledProcessError(1, ["borg", "mount"]) # mount fails
|
||||
]
|
||||
args = make_args("dummy.toml", "dummy.rc", str(tmp_path), archive="0")
|
||||
rc = run_mount(args)
|
||||
assert rc == 1
|
||||
err = capsys.readouterr().err
|
||||
assert "borg mount failed:" in err
|
||||
|
||||
|
||||
@mock.patch("locutus.mount.LocutusConfig")
|
||||
@mock.patch("os.path.isdir", return_value=True)
|
||||
@mock.patch("subprocess.run")
|
||||
def test_mount_exception_on_mount(mock_run, mock_isdir, mock_config, tmp_path, capsys):
|
||||
mock_config.return_value.get_repo.return_value = "/repo"
|
||||
mock_config.return_value.env = {}
|
||||
archives = ["a", "b", "c"]
|
||||
mock_run.side_effect = [
|
||||
mock.Mock(stdout="\n".join(archives) + "\n", returncode=0), # listing works
|
||||
Exception() # mount fails
|
||||
]
|
||||
args = make_args("dummy.toml", "dummy.rc", str(tmp_path), archive="0")
|
||||
rc = run_mount(args)
|
||||
assert rc == 1
|
||||
err = capsys.readouterr().err
|
||||
assert "borg mount failed (unexpected)" in err
|
||||
|
||||
Reference in New Issue
Block a user