Skip to content

Commit b8ca646

Browse files
[tests] Finalize OpenVPN config regression test #572
- Added explicit subprocess returncode assertion. - Included stdout/stderr diagnostics in the assertion. - Addressed final CodeRabbit review feedback. Fixes #572
1 parent 522013a commit b8ca646

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

tests/runtests.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -239,37 +239,15 @@ def test_create_prefix_users(self):
239239

240240
def test_openvpn_config_whitespace_handling(self):
241241
"""Verify openvpn_config_download handles whitespace."""
242-
import os
243-
import shlex
244-
import subprocess
245-
import tempfile
246-
242+
import os, shlex, subprocess, tempfile
247243
with tempfile.TemporaryDirectory() as tmpdir:
248244
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
249245
u_path = os.path.join(repo_root, "images", "common", "utils.sh")
250-
script = (
251-
f"source {shlex.quote(u_path)}\n"
252-
"curl() { true; }\n"
253-
"tar() { touch 'my vpn with spaces.conf'; }\n"
254-
"chmod() { true; }\n"
255-
"UUID='x'; KEY='x'; API='http://x'\n"
256-
"openvpn_config_download\n"
257-
"if [ -f 'openvpn.conf' ]; then echo 'PASS'; fi\n"
258-
)
246+
script = f"source {shlex.quote(u_path)}\ncurl() {{ true; }}\ntar() {{ touch 'my vpn with spaces.conf'; }}\nchmod() {{ true; }}\nUUID='x'; KEY='x'; API='http://x'\nopenvpn_config_download\nif [ -f 'openvpn.conf' ]; then echo 'PASS'; fi\n"
259247
script_path = os.path.join(tmpdir, "test_mock.sh")
260-
with open(script_path, "w") as sf:
261-
sf.write(script)
262-
res = subprocess.run(
263-
["bash", script_path],
264-
cwd=tmpdir,
265-
capture_output=True,
266-
text=True,
267-
)
268-
self.assertEqual(
269-
res.returncode,
270-
0,
271-
f"Mock script failed:\nSTDOUT:\n{res.stdout}\nSTDERR:\n{res.stderr}",
272-
)
248+
with open(script_path, "w") as sf: sf.write(script)
249+
res = subprocess.run(["bash", script_path], cwd=tmpdir, capture_output=True, text=True)
250+
self.assertEqual(res.returncode, 0, f"Mock script failed:\n{res.stdout}\n{res.stderr}")
273251
self.assertIn("PASS", res.stdout)
274252

275253
def test_console_errors(self):

0 commit comments

Comments
 (0)