Skip to content

Commit

Permalink
Add tests and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy committed Sep 3, 2024
1 parent c2a96fe commit d577afe
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog/64630.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed an intermittent issue with file.recurse where the state would
report failure even on success. Makes sure symlinks are created
after the target file is created
89 changes: 89 additions & 0 deletions tests/pytests/functional/states/file/test_recurse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
]


@pytest.fixture(scope="module")
def symlink(state_tree):
# Create directory structure
source_dir = state_tree / "test_symlink"
if not source_dir.is_dir():
source_dir.mkdir()
source_file = source_dir / "source_file.txt"
source_file.write_text("This is the source file...")
symlink_file = source_dir / "symlink"
symlink_file.symlink_to(source_file)
yield


@pytest.mark.parametrize("test", (False, True))
def test_recurse(file, tmp_path, grail, test):
"""
Expand Down Expand Up @@ -249,3 +262,79 @@ def test_issue_2726_mode_kwarg(modules, tmp_path, state_tree):
ret = modules.state.template_str("\n".join(good_template))
for state_run in ret:
assert state_run.result is True


def test_issue_64630_keep_symlinks_true(file, symlink, tmp_path):
"""
Make sure that symlinks are created and that there isn't an error
"""
target_dir = tmp_path / "test_symlink" # Target for the file.recurse state
target_file = target_dir / "source_file.txt"
target_symlink = target_dir / "symlink"

ret = file.recurse(
name=str(target_dir), source=f"salt://{target_dir.name}", keep_symlinks=True
)
assert ret.result is True

assert target_dir.exists()
assert target_file.is_file()
assert target_symlink.is_symlink()


def test_issue_64630_keep_symlinks_false(file, symlink, tmp_path):
"""
Make sure that symlinks are created and that there isn't an error
"""
target_dir = tmp_path / "test_symlink" # Target for the file.recurse state
target_file = target_dir / "source_file.txt"
target_symlink = target_dir / "symlink"

ret = file.recurse(
name=str(target_dir), source=f"salt://{target_dir.name}", keep_symlinks=False
)
assert ret.result is True

assert target_dir.exists()
assert target_file.is_file()
assert target_symlink.is_file()
assert target_file.read_text() == target_symlink.read_text()


def test_issue_64630_force_symlinks_true(file, symlink, tmp_path):
"""
Make sure that symlinks are created and that there isn't an error
"""
target_dir = tmp_path / "test_symlink" # Target for the file.recurse state
target_file = target_dir / "source_file.txt"
target_symlink = target_dir / "symlink"

ret = file.recurse(
name=str(target_dir), source=f"salt://{target_dir.name}", force_symlinks=True
)
assert ret.result is True

assert target_dir.exists()
assert target_file.is_file()
assert target_symlink.is_file()


def test_issue_64630_force_symlinks_keep_symlinks_true(file, symlink, tmp_path):
"""
Make sure that symlinks are created and that there isn't an error
"""
target_dir = tmp_path / "test_symlink" # Target for the file.recurse state
target_file = target_dir / "source_file.txt"
target_symlink = target_dir / "symlink"

ret = file.recurse(
name=str(target_dir),
source=f"salt://{target_dir.name}",
force_symlinks=True,
keep_symlinks=True,
)
assert ret.result is True

assert target_dir.exists()
assert target_file.is_file()
assert target_symlink.is_symlink()

0 comments on commit d577afe

Please sign in to comment.