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 all 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
16 changes: 10 additions & 6 deletions 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 @@ -49,9 +50,9 @@ def _create_base_folder_structure(self, component_name: str, component_test_conf
return os.path.realpath(dest_directory)

def _generate_std_files(self, stdout: str, stderr: str, output_path: str) -> None:
with open(os.path.join(output_path, "stdout.txt"), "w", encoding='utf-8') as stdout_file:
with open(os.path.join(output_path, "stdout.txt"), "w", encoding="utf-8") as stdout_file:
stdout_file.write(stdout)
with open(os.path.join(output_path, "stderr.txt"), "w", encoding='utf-8') as stderr_file:
with open(os.path.join(output_path, "stderr.txt"), "w", encoding="utf-8") as stderr_file:
stderr_file.write(stderr)

def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> str:
Expand All @@ -66,14 +67,17 @@ def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> s
"component_name": test_result_data.component_name,
"test_config": test_result_data.component_test_config,
"test_result": "PASS" if (test_result_data.exit_code == 0) else "FAIL",
"test_result_files": test_result_file
"test_result_files": test_result_file,
}
with open(os.path.join(output_path, "%s.yml" % test_result_data.component_name), "w", encoding='utf-8') as file:
with open(os.path.join(output_path, "%s.yml" % test_result_data.component_name), "w", encoding="utf-8") as file:
yaml.dump(outcome, file)
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]
if base_path.startswith("https://"):
return [f"{base_path}/{relative_path}/{urllib.parse.quote_plus(file)}" for file in files]
else:
return [os.path.join(base_path, relative_path, 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 Expand Up @@ -133,7 +137,7 @@ def save_test_result_data(self, test_result_data: TestResultData) -> None:


class TestResultsLogs(LogRecorder):
__test__ = False # type:ignore
__test__ = False # type:ignore
parent_class: TestRecorder

def __init__(self, parent_class: TestRecorder) -> None:
Expand Down
24 changes: 22 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 @@ -96,8 +96,28 @@ def test_update_absolute_file_paths(self, mock_local_cluster_logs: Mock, mock_re
"working-directory",
"https://ci.opensearch.org/ci/dbc/integ-test/"
)
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")])
file_path = test_recorder._update_absolute_file_paths(
["file1", "file2 with spaces"],
"working-directory",
"sub-directory"
)
self.assertEqual(file_path, [
os.path.join("working-directory", "sub-directory", "file1"),
os.path.join("working-directory", "sub-directory", "file2 with spaces")
])

@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, ["https://working-directory/sub-directory/A+long+test+case+name"])

@patch("os.walk")
@patch("test_workflow.test_recorder.test_recorder.TestResultsLogs")
Expand Down
Loading