Skip to content

Commit 34a0ef0

Browse files
fix: RemoteOperations::exec_command passes exec_env incorrectly (#11)
When we pass exec_env, we expect that they will be available within nested applications but it does not happen. The reason is in incorrect commands for setting environment variables - "name1=value1;name2=value2;<command>". We have to use "export name1=value1;export name2=value2;<command>". The new test "test_exec_command_with_exec_env__2" is added. It fails on old implementation and works fine on the new one.
1 parent 79fc61f commit 34a0ef0

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/remote_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ def _create_exec_env_list(exec_env: typing.Dict) -> typing.List[str]:
832832
assert type(envvar[1]) == str # noqa: E721
833833
qvalue = __class__._quote_envvar(envvar[1])
834834
assert type(qvalue) == str # noqa: E721
835-
result.append(envvar[0] + "=" + qvalue)
835+
result.append("export " + envvar[0] + "=" + qvalue)
836836
continue
837837

838838
return result

tests/test_os_ops_common.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,44 @@ def test_exec_command_with_exec_env(self, os_ops: OsOperations):
130130
assert type(response) == bytes # noqa: E721
131131
assert response == b'\n'
132132

133+
def test_exec_command_with_exec_env__2(self, os_ops: OsOperations):
134+
assert isinstance(os_ops, OsOperations)
135+
136+
RunConditions.skip_if_windows()
137+
138+
C_ENV_NAME = "TESTGRES_TEST__EXEC_ENV_20250414"
139+
140+
tmp_file_content = "echo ${{{}}}".format(C_ENV_NAME)
141+
142+
logging.info("content is [{}]".format(tmp_file_content))
143+
144+
tmp_file = os_ops.mkstemp()
145+
assert type(tmp_file) == str # noqa: E721
146+
assert tmp_file != ""
147+
148+
logging.info("file is [{}]".format(tmp_file))
149+
assert os_ops.path_exists(tmp_file)
150+
151+
os_ops.write(tmp_file, tmp_file_content)
152+
153+
cmd = ["sh", tmp_file]
154+
155+
exec_env = {C_ENV_NAME: "Hello!"}
156+
157+
response = os_ops.exec_command(cmd, exec_env=exec_env)
158+
assert response is not None
159+
assert type(response) == bytes # noqa: E721
160+
assert response == b'Hello!\n'
161+
162+
response = os_ops.exec_command(cmd)
163+
assert response is not None
164+
assert type(response) == bytes # noqa: E721
165+
assert response == b'\n'
166+
167+
os_ops.remove_file(tmp_file)
168+
assert not os_ops.path_exists(tmp_file)
169+
return
170+
133171
def test_exec_command_with_cwd(self, os_ops: OsOperations):
134172
assert isinstance(os_ops, OsOperations)
135173

0 commit comments

Comments
 (0)