Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL encode test result files #4574

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/test_workflow/test_recorder/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
import shutil
import urllib.parse
from typing import Any

import yaml
Expand Down Expand Up @@ -73,7 +74,14 @@ def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> s
return os.path.realpath("%s.yml" % test_result_data.component_name)

def _update_absolute_file_paths(self, files: list, base_path: str, relative_path: str) -> list:
return [os.path.join(base_path, relative_path, file) for file in files]
return [
os.path.join(
base_path,
relative_path,
urllib.parse.quote_plus(file) if base_path.startswith("https://") else file
)
for file in files
]

# get a list of files within directory with relative paths.
def _get_list_files(self, dir: str) -> list:
Expand Down
17 changes: 15 additions & 2 deletions tests/tests_test_workflow/test_recorder/test_test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ def test_update_absolute_file_paths(self, mock_local_cluster_logs: Mock, mock_re
file_path = test_recorder._update_absolute_file_paths(["file1", "file2"], "working-directory", "sub-directory")
self.assertEqual(file_path, [os.path.join("working-directory", "sub-directory", "file1"), os.path.join("working-directory", "sub-directory", "file2")])

@patch("test_workflow.test_recorder.test_recorder.TestResultsLogs")
@patch("test_workflow.test_recorder.test_recorder.RemoteClusterLogs")
@patch("test_workflow.test_recorder.test_recorder.LocalClusterLogs")
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:
test_recorder = TestRecorder(
"1234",
"integ-test",
"working-directory",
"https://ci.opensearch.org/ci/dbc/integ-test/"
)
file_path = test_recorder._update_absolute_file_paths(["A long test case name"], "https://working-directory", "sub-directory")
self.assertEqual(file_path, [os.path.join("https://working-directory", "sub-directory", "A+long+test+case+name")])

@patch("os.walk")
@patch("test_workflow.test_recorder.test_recorder.TestResultsLogs")
@patch("test_workflow.test_recorder.test_recorder.RemoteClusterLogs")
Expand All @@ -110,9 +123,9 @@ def test_get_list_files(self, mock_local_cluster_logs: Mock, mock_remote_cluster
"working-directory",
"https://ci.opensearch.org/ci/dbc/integ-test/"
)
mock_os_walk.return_value = [("mock_dir", (), ("file1", "file2"))]
mock_os_walk.return_value = [("mock_dir", (), ("file1", "file2 with spaces"))]
list_files = test_recorder._get_list_files("mock_dir")
self.assertEqual(list_files, ["file1", "file2"])
self.assertEqual(list_files, ["file1", "file2 with spaces"])

@patch("builtins.open", new_callable=mock_open)
def test_generate_std_files(self, mock_open: Mock, *mock: Any) -> None:
Expand Down
Loading