@@ -107,6 +107,25 @@ def test_rmd_to_pdf_rendering(self, rstudio_image: docker.models.images.Image) -
107
107
finally :
108
108
docker_utils .NotebookContainer (container ).stop (timeout = 0 )
109
109
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
+
110
129
@allure .issue ("RHOAIENG-16604" )
111
130
def test_http_proxy_env_propagates (self , rstudio_image : str , subtests : pytest_subtests .plugin .SubTests ) -> None :
112
131
"""
@@ -133,15 +152,25 @@ class TestCase(NamedTuple):
133
152
# We need to wait for the IDE to be completely loaded so that the envs are processed properly.
134
153
container .start (wait_for_readiness = True )
135
154
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.
137
156
for tc in test_cases :
138
157
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
+
141
160
finally :
142
161
docker_utils .NotebookContainer (container ).stop (timeout = 0 )
143
162
144
163
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
+
145
174
def check_call (container : WorkbenchContainer , cmd : str ) -> int :
146
175
"""Like subprocess.check_output, but in a container."""
147
176
logging .debug (_ ("Running command" , cmd = cmd ))
0 commit comments