Skip to content

Commit

Permalink
ulwgl_test: add tests when symlinking to steamuser or user
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Feb 26, 2024
1 parent c488676 commit 2ea4c71
Showing 1 changed file with 113 additions and 15 deletions.
128 changes: 113 additions & 15 deletions ulwgl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ulwgl_plugins
import ulwgl_dl_util
import tarfile
import ulwgl_util


class TestGameLauncher(unittest.TestCase):
Expand Down Expand Up @@ -845,32 +846,129 @@ def test_setup_pfx_mv(self):
Path(self.test_file + "/pfx").is_symlink(), "Expected pfx to be a symlink"
)

# Check if the symlink is in its unexpanded form
self.assertEqual(
Path(self.test_file + "/pfx").readlink().as_posix(),
Path(unexpanded_path).expanduser().as_posix(),
def test_setup_pfx_symlinks_else(self):
"""Test setup_pfx in the case both steamuser and unixuser exist in some form.
Tests the case when they are symlinks
An error should not be raised and we should just do nothing
"""
result = None
pattern = r"^/home/[\w\d]+"
user = ulwgl_util.UnixUser()
unexpanded_path = re.sub(
pattern,
"~",
Path(
Path(self.test_file).cwd().as_posix() + "/" + self.test_file
).as_posix(),
)

# Create only the dir
Path(unexpanded_path).joinpath("drive_c/users").expanduser().mkdir(
parents=True, exist_ok=True
)

# Create the symlink to the test file itself
Path(unexpanded_path).joinpath("drive_c/users").joinpath(
user.get_user()
).expanduser().symlink_to(Path(self.test_file).absolute())
Path(unexpanded_path).joinpath("drive_c/users").joinpath(
"steamuser"
).expanduser().symlink_to(Path(self.test_file).absolute())

result = ulwgl_run.setup_pfx(unexpanded_path)

self.assertIsNone(
result,
"Expected None when calling setup_pfx",
)

old_link = Path(self.test_file + "/pfx").resolve()
def test_setup_pfx_symlinks_unixuser(self):
"""Test setup_pfx for symbolic link to steamuser.
# Rename the dir and replicate passing a new WINEPREFIX
new_dir = Path(unexpanded_path).expanduser().rename("foo")
new_unexpanded_path = re.sub(
Tests the case when the steamuser dir does not exist and user dir exists
In this case, create: steamuser -> user
"""
result = None
pattern = r"^/home/[\w\d]+"
user = ulwgl_util.UnixUser()
unexpanded_path = re.sub(
pattern,
"~",
new_dir.cwd().joinpath("foo").as_posix(),
Path(
Path(self.test_file).cwd().as_posix() + "/" + self.test_file
).as_posix(),
)

ulwgl_run.setup_pfx(new_unexpanded_path)
# Create only the user dir
Path(unexpanded_path).joinpath("drive_c/users").joinpath(
user.get_user()
).expanduser().mkdir(parents=True, exist_ok=True)

result = ulwgl_run.setup_pfx(unexpanded_path)

self.assertIsNone(
result,
"Expected None when creating symbolic link to WINE prefix and tracked_files file",
)

new_link = Path("foo/pfx").resolve()
# Verify steamuser -> unix user
self.assertTrue(
old_link is not new_link,
"Expected the symbolic link to change after moving the WINEPREFIX",
Path(self.test_file).joinpath("drive_c/users/steamuser").is_symlink(),
"Expected steamuser to be a symbolic link",
)
self.assertEqual(
Path(self.test_file).joinpath("drive_c/users/steamuser").readlink(),
Path(user.get_user()),
"Expected steamuser -> user",
)

def test_setup_pfx_symlinks_steamuser(self):
"""Test setup_pfx for symbolic link to wine.
Tests the case when only steamuser exist and the user dir does not exist
"""
result = None
user = ulwgl_util.UnixUser()
pattern = r"^/home/[\w\d]+"
unexpanded_path = re.sub(
pattern,
"~",
Path(
Path(self.test_file).cwd().as_posix() + "/" + self.test_file
).as_posix(),
)

# Create the steamuser dir
Path(unexpanded_path + "/drive_c/users/steamuser").expanduser().mkdir(
parents=True, exist_ok=True
)

result = ulwgl_run.setup_pfx(unexpanded_path)

self.assertIsNone(
result,
"Expected None when creating symbolic link to WINE prefix and tracked_files file",
)

if new_link.exists():
rmtree(new_link.as_posix())
# Verify unixuser -> steamuser
self.assertTrue(
Path(self.test_file + "/drive_c/users/steamuser").is_dir(),
"Expected steamuser to be created",
)
self.assertTrue(
Path(unexpanded_path + "/drive_c/users/" + user.get_user())
.expanduser()
.is_symlink(),
"Expected symbolic link for unixuser",
)
self.assertEqual(
Path(self.test_file)
.joinpath(f"drive_c/users/{user.get_user()}")
.readlink(),
Path("steamuser"),
"Expected unixuser -> steamuser",
)

def test_setup_pfx_symlinks(self):
"""Test setup_pfx for valid symlinks.
Expand Down

0 comments on commit 2ea4c71

Please sign in to comment.