Skip to content

Commit 027e593

Browse files
singiamtelktf
authored andcommitted
Add tests for multiline env variables
1 parent 2eaa5e1 commit 027e593

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_cmd.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ def test_DockerRunner_with_env_vars(self, mock_getstatusoutput, mock_getoutput):
6868
getstatusoutput_docker("echo test")
6969
mock_getstatusoutput.assert_called_with("env TEST_VAR=test_value ANOTHER_VAR=another_value /bin/bash -c 'echo test'", cwd=None)
7070

71+
@mock.patch("alibuild_helpers.cmd.getoutput")
72+
@mock.patch("alibuild_helpers.cmd.getstatusoutput")
73+
def test_DockerRunner_multiline_env_var(self, mock_getstatusoutput, mock_getoutput):
74+
multiline_value = "line1\nline2\nline3"
75+
extra_env = {"MULTILINE_VAR": multiline_value}
76+
77+
with DockerRunner("", extra_env=extra_env) as getstatusoutput_docker:
78+
mock_getoutput.assert_not_called()
79+
getstatusoutput_docker("echo test")
80+
mock_getstatusoutput.assert_called_with("env MULTILINE_VAR='line1\nline2\nline3' /bin/bash -c 'echo test'", cwd=None)
81+
82+
@mock.patch("alibuild_helpers.cmd.getoutput")
83+
@mock.patch("alibuild_helpers.cmd.getstatusoutput")
84+
def test_DockerRunner_env_var_with_semicolon(self, mock_getstatusoutput, mock_getoutput):
85+
semicolon_value = "value1;value2;value3"
86+
extra_env = {"SEMICOLON_VAR": semicolon_value}
87+
88+
with DockerRunner("", extra_env=extra_env) as getstatusoutput_docker:
89+
mock_getoutput.assert_not_called()
90+
getstatusoutput_docker("echo test")
91+
mock_getstatusoutput.assert_called_with("env SEMICOLON_VAR='value1;value2;value3' /bin/bash -c 'echo test'", cwd=None)
92+
7193

7294
if __name__ == '__main__':
7395
unittest.main()

0 commit comments

Comments
 (0)