Fix unit test on Linux

This commit is contained in:
twangboy 2024-09-12 13:27:44 -06:00
parent 554da0c21e
commit a5c3c18442
No known key found for this signature in database
GPG key ID: ED267D5C0DE6F8A6
2 changed files with 10 additions and 4 deletions

View file

@ -568,7 +568,7 @@ def _gen_recurse_managed_files(
for file_dest, file_src in managed_files:
# We need to convert relpath to fullpath. We're using pathlib to
# be platform-agnostic
symlink_full_path = pathlib.Path(f"{name}\\{link_src_relpath}")
symlink_full_path = pathlib.Path(f"{name}{os.sep}{link_src_relpath}")
file_dest_full_path = pathlib.Path(file_dest)
if symlink_full_path == file_dest_full_path:
new_managed_files.append(

View file

@ -1,4 +1,5 @@
import logging
import os
import pathlib
import pytest
@ -18,7 +19,7 @@ def test__gen_recurse_managed_files():
"""
Test _gen_recurse_managed_files to make sure it puts symlinks at the end of the list of files.
"""
target_dir = pathlib.Path("\\some\\path\\target")
target_dir = pathlib.Path(f"{os.sep}some{os.sep}path{os.sep}target")
cp_list_master = MagicMock(
return_value=[
"target/symlink",
@ -28,7 +29,9 @@ def test__gen_recurse_managed_files():
],
)
cp_list_master_symlinks = MagicMock(
return_value={"target/symlink": f"{target_dir}\\not_a_symlink\\symlink"}
return_value={
"target/symlink": f"{target_dir}{os.sep}not_a_symlink{os.sep}symlink"
}
)
patch_salt = {
"cp.list_master": cp_list_master,
@ -38,5 +41,8 @@ def test__gen_recurse_managed_files():
files, dirs, links, keep = filestate._gen_recurse_managed_files(
name=str(target_dir), source=f"salt://{target_dir.name}", keep_symlinks=True
)
expected = ("\\some\\path\\target\\symlink", "salt://target/symlink?saltenv=base")
expected = (
f"{os.sep}some{os.sep}path{os.sep}target{os.sep}symlink",
"salt://target/symlink?saltenv=base",
)
assert files[-1] == expected