Skip to content

Commit

Permalink
umu_test: add tests for check_runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Apr 28, 2024
1 parent fe26582 commit 2d85571
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion umu/umu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path
from shutil import rmtree, copytree, copy
from pwd import getpwuid
from subprocess import CompletedProcess


class TestGameLauncher(unittest.TestCase):
Expand Down Expand Up @@ -111,8 +112,9 @@ def setUp(self):
Path(self.test_user_share, "umu").touch()

# Mock pressure vessel
Path(self.test_user_share, "pressure-vessel").mkdir()
Path(self.test_user_share, "pressure-vessel", "bin").mkdir(parents=True)
Path(self.test_user_share, "pressure-vessel", "foo").touch()
Path(self.test_user_share, "pressure-vessel", "bin", "pv-verify").touch()

# Mock the proton file in the dir
self.test_proton_dir.joinpath("proton").touch(exist_ok=True)
Expand Down Expand Up @@ -155,6 +157,37 @@ def tearDown(self):
if self.test_local_share.exists():
rmtree(self.test_local_share.as_posix())

def test_check_runtime(self):
"""Test check_runtime when pv-verify does not exist.
check_runtime calls pv-verify to verify the integrity of the runtime
archive's contents, and will only be called when restoring or setting
up the runtime
If the pv-verify binary does not exist, a warning should be logged and
the function should return
"""
json_root = umu_util._get_json(self.test_user_share, "umu_version.json")
self.test_user_share.joinpath("pressure-vessel", "bin", "pv-verify").unlink()
result = umu_util.check_runtime(self.test_user_share, json_root)
self.assertEqual(result, 1, "Expected the exit code 1")

def test_check_runtime_fail(self):
"""Test check_runtime when runtime validation fails."""
json_root = umu_util._get_json(self.test_user_share, "umu_version.json")
mock = CompletedProcess(["foo"], 1)
with patch.object(umu_util, "run", return_value=mock):
result = umu_util.check_runtime(self.test_user_share, json_root)
self.assertEqual(result, 1, "Expected the exit code 1")

def test_check_runtime_success(self):
"""Test check_runtime when runtime validation succeeds."""
json_root = umu_util._get_json(self.test_user_share, "umu_version.json")
mock = CompletedProcess(["foo"], 0)
with patch.object(umu_util, "run", return_value=mock):
result = umu_util.check_runtime(self.test_user_share, json_root)
self.assertEqual(result, 0, "Expected the exit code 0")

def test_move(self):
"""Test _move when copying a directory or a file.
Expand Down

0 comments on commit 2d85571

Please sign in to comment.