Skip to content

Commit befb59f

Browse files
authoredApr 1, 2024
URL encode test result files (#4574)
Signed-off-by: Simeon Widdis <sawiddis@amazon.com> Signed-off-by: Simeon Widdis <sawiddis@gmail.com>
1 parent 6a09aeb commit befb59f

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed
 

‎src/test_workflow/test_recorder/test_recorder.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import os
1010
import shutil
11+
import urllib.parse
1112
from typing import Any
1213

1314
import yaml
@@ -49,9 +50,9 @@ def _create_base_folder_structure(self, component_name: str, component_test_conf
4950
return os.path.realpath(dest_directory)
5051

5152
def _generate_std_files(self, stdout: str, stderr: str, output_path: str) -> None:
52-
with open(os.path.join(output_path, "stdout.txt"), "w", encoding='utf-8') as stdout_file:
53+
with open(os.path.join(output_path, "stdout.txt"), "w", encoding="utf-8") as stdout_file:
5354
stdout_file.write(stdout)
54-
with open(os.path.join(output_path, "stderr.txt"), "w", encoding='utf-8') as stderr_file:
55+
with open(os.path.join(output_path, "stderr.txt"), "w", encoding="utf-8") as stderr_file:
5556
stderr_file.write(stderr)
5657

5758
def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> str:
@@ -66,14 +67,17 @@ def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> s
6667
"component_name": test_result_data.component_name,
6768
"test_config": test_result_data.component_test_config,
6869
"test_result": "PASS" if (test_result_data.exit_code == 0) else "FAIL",
69-
"test_result_files": test_result_file
70+
"test_result_files": test_result_file,
7071
}
71-
with open(os.path.join(output_path, "%s.yml" % test_result_data.component_name), "w", encoding='utf-8') as file:
72+
with open(os.path.join(output_path, "%s.yml" % test_result_data.component_name), "w", encoding="utf-8") as file:
7273
yaml.dump(outcome, file)
7374
return os.path.realpath("%s.yml" % test_result_data.component_name)
7475

7576
def _update_absolute_file_paths(self, files: list, base_path: str, relative_path: str) -> list:
76-
return [os.path.join(base_path, relative_path, file) for file in files]
77+
if base_path.startswith("https://"):
78+
return [f"{base_path}/{relative_path}/{urllib.parse.quote_plus(file)}" for file in files]
79+
else:
80+
return [os.path.join(base_path, relative_path, file) for file in files]
7781

7882
# get a list of files within directory with relative paths.
7983
def _get_list_files(self, dir: str) -> list:
@@ -133,7 +137,7 @@ def save_test_result_data(self, test_result_data: TestResultData) -> None:
133137

134138

135139
class TestResultsLogs(LogRecorder):
136-
__test__ = False # type:ignore
140+
__test__ = False # type:ignore
137141
parent_class: TestRecorder
138142

139143
def __init__(self, parent_class: TestRecorder) -> None:

‎tests/tests_test_workflow/test_recorder/test_test_recorder.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,28 @@ def test_update_absolute_file_paths(self, mock_local_cluster_logs: Mock, mock_re
9696
"working-directory",
9797
"https://ci.opensearch.org/ci/dbc/integ-test/"
9898
)
99-
file_path = test_recorder._update_absolute_file_paths(["file1", "file2"], "working-directory", "sub-directory")
100-
self.assertEqual(file_path, [os.path.join("working-directory", "sub-directory", "file1"), os.path.join("working-directory", "sub-directory", "file2")])
99+
file_path = test_recorder._update_absolute_file_paths(
100+
["file1", "file2 with spaces"],
101+
"working-directory",
102+
"sub-directory"
103+
)
104+
self.assertEqual(file_path, [
105+
os.path.join("working-directory", "sub-directory", "file1"),
106+
os.path.join("working-directory", "sub-directory", "file2 with spaces")
107+
])
108+
109+
@patch("test_workflow.test_recorder.test_recorder.TestResultsLogs")
110+
@patch("test_workflow.test_recorder.test_recorder.RemoteClusterLogs")
111+
@patch("test_workflow.test_recorder.test_recorder.LocalClusterLogs")
112+
def test_update_absolute_file_paths_escaping(self, mock_local_cluster_logs: Mock, mock_remote_cluster_logs: Mock, mock_test_results_logs: Mock, *mock: Any) -> None:
113+
test_recorder = TestRecorder(
114+
"1234",
115+
"integ-test",
116+
"working-directory",
117+
"https://ci.opensearch.org/ci/dbc/integ-test/"
118+
)
119+
file_path = test_recorder._update_absolute_file_paths(["A long test case name"], "https://working-directory", "sub-directory")
120+
self.assertEqual(file_path, ["https://working-directory/sub-directory/A+long+test+case+name"])
101121

102122
@patch("os.walk")
103123
@patch("test_workflow.test_recorder.test_recorder.TestResultsLogs")

0 commit comments

Comments
 (0)