|
5 | 5 | import salt.utils.files
|
6 | 6 | import salt.utils.path
|
7 | 7 | import salt.utils.platform
|
| 8 | +import salt.utils.win_dacl |
8 | 9 | import salt.utils.win_functions
|
9 | 10 |
|
10 | 11 | pytestmark = [
|
@@ -290,6 +291,65 @@ def test_directory_clean_require_in(modules, tmp_path, state_tree):
|
290 | 291 | assert wrong_file.exists() is False
|
291 | 292 |
|
292 | 293 |
|
| 294 | +def test_directory_clean_require_in_good_message(modules, tmp_path, state_tree): |
| 295 | + """ |
| 296 | + file.directory test with clean=True and require_in file, |
| 297 | + the comment cannot be "removed": "Removed due to clean" |
| 298 | + """ |
| 299 | + name = tmp_path / "b-directory" |
| 300 | + name.mkdir() |
| 301 | + if IS_WINDOWS: |
| 302 | + principal = salt.utils.win_functions.get_current_user() |
| 303 | + salt.utils.win_dacl.set_owner(obj_name=str(name), principal=principal) |
| 304 | + dir = name / "one" |
| 305 | + dir.mkdir() |
| 306 | + good_file = dir / "good-file" |
| 307 | + good_file.write_text("good") |
| 308 | + |
| 309 | + assert good_file.exists() |
| 310 | + assert good_file.is_file() |
| 311 | + |
| 312 | + assert name.exists() |
| 313 | + assert name.is_dir() |
| 314 | + |
| 315 | + assert dir.exists() |
| 316 | + assert dir.is_dir() |
| 317 | + |
| 318 | + sls_contents = """ |
| 319 | + some_dir: |
| 320 | + file.directory: |
| 321 | + - name: {name} |
| 322 | + - clean: true |
| 323 | + {good_file}: |
| 324 | + file.managed: |
| 325 | + - require_in: |
| 326 | + - file: some_dir |
| 327 | + """.format( |
| 328 | + name=name, good_file=good_file |
| 329 | + ) |
| 330 | + |
| 331 | + with pytest.helpers.temp_file("clean-require-in.sls", sls_contents, state_tree): |
| 332 | + ret = modules.state.sls("clean-require-in") |
| 333 | + expected_file = ( |
| 334 | + f"File {good_file} exists with proper permissions. No changes made." |
| 335 | + ) |
| 336 | + for state_run in ret: |
| 337 | + print("changes", state_run.changes) |
| 338 | + if IS_WINDOWS: |
| 339 | + if state_run.changes: |
| 340 | + expected_dir = f"Directory {name} updated" |
| 341 | + else: |
| 342 | + expected_dir = f"Directory {name} is in the correct state" |
| 343 | + else: |
| 344 | + expected_dir = f"The directory {name} is in the correct state" |
| 345 | + assert dir.exists() |
| 346 | + assert good_file.exists() |
| 347 | + assert good_file.read_text() == "good" |
| 348 | + assert ( |
| 349 | + state_run.comment == expected_file or state_run.comment == expected_dir |
| 350 | + ) |
| 351 | + |
| 352 | + |
293 | 353 | def test_directory_clean_require_in_with_id(modules, tmp_path, state_tree):
|
294 | 354 | """
|
295 | 355 | file.directory test with clean=True and require_in file with an ID
|
|
0 commit comments