mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add test case
This commit is contained in:
parent
3e8fb1a06a
commit
46ef29b9af
1 changed files with 27 additions and 0 deletions
27
tests/pytests/unit/utils/test_atomicfile.py
Normal file
27
tests/pytests/unit/utils/test_atomicfile.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
"""
|
||||
Tests for atomicfile utility module.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.utils.files
|
||||
from salt.utils.atomicfile import atomic_open
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason="Not a Windows test")
|
||||
def test_atomicfile_respects_umask(tmp_path):
|
||||
"""
|
||||
Test that creating a file using atomic_open respects the umask, instead of
|
||||
creating the file with 0600 perms.
|
||||
"""
|
||||
new_file = tmp_path / "foo"
|
||||
contents = "bar"
|
||||
|
||||
# Set the umask specifically for this test so that we know what the mode of
|
||||
# the created file should be.
|
||||
with salt.utils.files.set_umask(0o022):
|
||||
with atomic_open(str(new_file), "w") as fh_:
|
||||
fh_.write(contents)
|
||||
|
||||
assert new_file.read_text() == contents
|
||||
assert oct(new_file.stat().st_mode)[-3:] == "644"
|
Loading…
Add table
Reference in a new issue