Skip to content

Commit 1b7c0fc

Browse files
test: use writable non-root caches
Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
1 parent d908828 commit 1b7c0fc

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

tests/coverage.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ export PROJECT_ROOT
2323
export USER="${USER:-nemo-ci}"
2424
export LOGNAME="${LOGNAME:-$USER}"
2525

26+
# The CI image may provide a root-owned cache. Redirect it only when it is not
27+
# writable so existing writable cache configuration remains unchanged.
28+
if [ -n "${XDG_CACHE_HOME:-}" ] && [ ! -w "$XDG_CACHE_HOME" ]; then
29+
XDG_CACHE_HOME="${HOME:?HOME must be set}/.cache"
30+
elif [ -z "${XDG_CACHE_HOME:-}" ]; then
31+
XDG_CACHE_HOME="${HOME:?HOME must be set}/.cache"
32+
fi
33+
export XDG_CACHE_HOME
34+
2635
cd "$PROJECT_ROOT"

tests/unit_tests/deploy/test_coverage.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_shell_coverage_setup_does_not_require_git(checkout, tmp_path):
6060
check=True,
6161
capture_output=True,
6262
text=True,
63-
env={"PATH": "/usr/bin:/bin"},
63+
env={"HOME": str(tmp_path / "home"), "PATH": "/usr/bin:/bin"},
6464
)
6565

6666
expected_root = str(mounted_checkout.resolve())
@@ -88,3 +88,49 @@ def test_shell_coverage_setup_provides_container_identity(tmp_path):
8888
)
8989

9090
assert result.stdout.splitlines() == ["nemo-ci", "nemo-ci"]
91+
92+
93+
@pytest.mark.parametrize("configured_cache", [None, Path("/root-owned-cache")])
94+
def test_shell_coverage_setup_provides_writable_cache(configured_cache, tmp_path):
95+
home = tmp_path / "home"
96+
home.mkdir()
97+
env = {"HOME": str(home), "PATH": "/usr/bin:/bin"}
98+
if configured_cache is not None:
99+
env["XDG_CACHE_HOME"] = str(configured_cache)
100+
101+
result = subprocess.run(
102+
[
103+
"bash",
104+
"-c",
105+
'source "$1"; printf "%s\\n" "$XDG_CACHE_HOME"',
106+
"coverage-test",
107+
str(PROJECT_ROOT / "tests" / "coverage.sh"),
108+
],
109+
check=True,
110+
capture_output=True,
111+
text=True,
112+
cwd=tmp_path,
113+
env=env,
114+
)
115+
116+
assert result.stdout.strip() == str(home / ".cache")
117+
118+
119+
def test_shell_coverage_setup_preserves_writable_cache(tmp_path):
120+
cache = tmp_path / "cache"
121+
cache.mkdir()
122+
result = subprocess.run(
123+
[
124+
"bash",
125+
"-c",
126+
'source "$1"; printf "%s\\n" "$XDG_CACHE_HOME"',
127+
"coverage-test",
128+
str(PROJECT_ROOT / "tests" / "coverage.sh"),
129+
],
130+
check=True,
131+
capture_output=True,
132+
text=True,
133+
cwd=tmp_path,
134+
env={"HOME": str(tmp_path / "home"), "PATH": "/usr/bin:/bin", "XDG_CACHE_HOME": str(cache)},
135+
)
136+
assert result.stdout.strip() == str(cache)

0 commit comments

Comments
 (0)