Skip to content

Commit 0b59250

Browse files
authored
RHOAIENG-23584: test(run-rstudio.sh): fix tests to more correctly check for exposed env variables (#1033)
1 parent c6534cc commit 0b59250

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

tests/containers/workbenches/rstudio/rstudio_test.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ def test_rmd_to_pdf_rendering(self, rstudio_image: docker.models.images.Image) -
107107
finally:
108108
docker_utils.NotebookContainer(container).stop(timeout=0)
109109

110+
@allure.issue("RHOAIENG-23584")
111+
def test_arbitrary_env_propagates_unchanged(self, rstudio_image: str) -> None:
112+
"""
113+
Checks that environment variables are propagated into the RStudio environment.
114+
"""
115+
116+
container = WorkbenchContainer(image=rstudio_image, user=1000, group_add=[0])
117+
container.with_env("SOME_VARIABLE", "Some Value")
118+
119+
try:
120+
# We need to wait for the IDE to be completely loaded so that the envs are processed properly.
121+
container.start(wait_for_readiness=True)
122+
123+
# Once the RStudio IDE is fully up and running, the processed envs should include the variable.
124+
assert_has_env_variable(container, "SOME_VARIABLE", "Some Value")
125+
126+
finally:
127+
docker_utils.NotebookContainer(container).stop(timeout=0)
128+
110129
@allure.issue("RHOAIENG-16604")
111130
def test_http_proxy_env_propagates(self, rstudio_image: str, subtests: pytest_subtests.plugin.SubTests) -> None:
112131
"""
@@ -133,15 +152,25 @@ class TestCase(NamedTuple):
133152
# We need to wait for the IDE to be completely loaded so that the envs are processed properly.
134153
container.start(wait_for_readiness=True)
135154

136-
# Once the RStudio IDE is fully up and running, the processed envs should includ also lowercased proxy configs.
155+
# Once the RStudio IDE is fully up and running, the processed envs should include also lowercased proxy configs.
137156
for tc in test_cases:
138157
with subtests.test(tc.name):
139-
output = check_output(container, f"/usr/bin/R --quiet --no-echo -e 'Sys.getenv(\"{tc.name_lc}\")'")
140-
assert '"' + tc.value + '"' in output
158+
assert_has_env_variable(container, tc.name_lc, tc.value)
159+
141160
finally:
142161
docker_utils.NotebookContainer(container).stop(timeout=0)
143162

144163

164+
def assert_has_env_variable(container: WorkbenchContainer, name: str, value: str) -> None:
165+
"""Checks that the given env variable is present in the RStudio environment."""
166+
output = check_output(
167+
container,
168+
# ignore the environment coming in and let R to set up environment from scratch
169+
f"/usr/bin/env --ignore-environment /usr/bin/R --quiet --no-echo -e 'Sys.getenv(\"{name}\")'",
170+
)
171+
assert f'"{value}"' in output
172+
173+
145174
def check_call(container: WorkbenchContainer, cmd: str) -> int:
146175
"""Like subprocess.check_output, but in a container."""
147176
logging.debug(_("Running command", cmd=cmd))

0 commit comments

Comments
 (0)