Skip to content

Commit be0ceae

Browse files
tests: Add test to verify umask is set properly in the container
1 parent f73faf2 commit be0ceae

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import scuba.__main__ as main
1818
import scuba.dockerutil
19+
import scuba.utils
1920

2021
from .const import DOCKER_IMAGE
2122
from .utils import (
@@ -1186,3 +1187,26 @@ def test_volumes_named(self) -> None:
11861187
# Invoke scuba again: Verify the file is still there
11871188
out, _ = run_scuba(["/bin/sh", "-c", f"cat {test_path}"])
11881189
assert_str_equalish(out, test_str)
1190+
1191+
1192+
class TestMainUmask(MainTest):
1193+
def test_umask(self) -> None:
1194+
"""Verify umask is set properly"""
1195+
SCUBA_YML.write_text(f"image: {DOCKER_IMAGE}")
1196+
1197+
FAKE_UMASK = 0o123 # unlikely
1198+
1199+
def mocked_get_umask() -> int:
1200+
return FAKE_UMASK
1201+
1202+
# http://alexmarandon.com/articles/python_mock_gotchas/#patching-in-the-wrong-place
1203+
# http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch
1204+
with mock.patch("scuba.scuba.get_umask", side_effect=mocked_get_umask) as m:
1205+
args = ["/bin/sh", "-c", "umask"]
1206+
out, _ = run_scuba(args)
1207+
1208+
m.assert_called_once()
1209+
1210+
assert out.startswith("0")
1211+
result_umask = int(out, 8)
1212+
assert result_umask == FAKE_UMASK

0 commit comments

Comments
 (0)