Skip to content

Commit

Permalink
ulwgl_test: add tests for unix username to steamuser
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Feb 22, 2024
1 parent 9d02075 commit a5dff03
Showing 1 changed file with 125 additions and 16 deletions.
141 changes: 125 additions & 16 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,35 +846,132 @@ 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/[a-zA-Z]+"
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
)

old_link = Path(self.test_file + "/pfx").resolve()
# 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)

# Rename the dir and replicate passing a new WINEPREFIX
new_dir = Path(unexpanded_path).expanduser().rename("foo")
new_unexpanded_path = re.sub(
self.assertIsNone(
result,
"Expected None when calling setup_pfx",
)

def test_setup_pfx_symlinks_unixuser(self):
"""Test setup_pfx for symbolic link to steamuser.
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/[a-zA-Z]+"
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").resolve(),
Path(self.test_file)
.joinpath(f"drive_c/users/{user.get_user()}")
.absolute(),
"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/[a-zA-Z]+"
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)

if new_link.exists():
rmtree(new_link.as_posix())
self.assertIsNone(
result,
"Expected None when creating symbolic link to WINE prefix and tracked_files file",
)

# 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/" + Path().home().name)
.expanduser()
.is_symlink(),
"Expected symbolic link for unixuser",
)
self.assertEqual(
Path(self.test_file).joinpath(f"drive_c/users/{user.get_user()}").resolve(),
Path(self.test_file).joinpath("drive_c/users/steamuser").absolute(),
"Expected unixuser -> steamuser",
)

def test_setup_pfx_symlinks(self):
"""Test _setup_pfx for valid symlinks.
"""Test setup_pfx for valid symlinks.
Ensure that symbolic links to the WINE prefix (pfx) are always in expanded form when passed an unexpanded path.
For example:
Expand Down Expand Up @@ -958,6 +1056,17 @@ def test_setup_pfx(self):
Path(self.test_file + "/tracked_files").is_file(),
"Expected tracked_files to be a file",
)
# For new prefixes, steamuser should exist and a user symlink
self.assertTrue(
Path(self.test_file + "/drive_c/users/steamuser").is_dir(),
"Expected steamuser to be created",
)
self.assertTrue(
Path(self.test_file + "/drive_c/users/" + Path().home().name)
.expanduser()
.is_symlink(),
"Expected symlink of username -> steamuser",
)

def test_parse_args(self):
"""Test parse_args with no options.
Expand Down

0 comments on commit a5dff03

Please sign in to comment.