Skip to content

Commit

Permalink
Update the URL join
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <zelinhao@amazon.com>
  • Loading branch information
zelinh committed May 18, 2023
1 parent 2f3984b commit 5991ed9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/test_workflow/test_recorder/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import shutil
from typing import Any
from urllib.parse import urljoin

import yaml

Expand Down Expand Up @@ -38,7 +37,7 @@ def __init__(self, test_run_id: str, test_type: str, tests_dir: str, base_path:

def _get_file_path(self, base_path: str, component_name: str, component_test_config: str) -> str:
if base_path.startswith("https://"):
file_path = urljoin(base_path, "/".join(["test-results", str(self.test_run_id), self.test_type, component_name, component_test_config]))
file_path = "/".join([base_path.strip("/"), "test-results", str(self.test_run_id), self.test_type, component_name, component_test_config])
else:
file_path = self._create_base_folder_structure(component_name, component_test_config)
return file_path
Expand Down Expand Up @@ -149,8 +148,7 @@ def __init__(self, parent_class: TestRecorder) -> None:
self.parent_class = parent_class

def save_test_result_data(self, test_result_data: TestResultData) -> None:
base = self.parent_class._create_base_folder_structure(test_result_data.component_name, test_result_data.component_test_config)
dest_directory = os.path.join(base)
dest_directory = self.parent_class._create_base_folder_structure(test_result_data.component_name, test_result_data.component_test_config)
logging.info(f"Recording component test results for {test_result_data.component_name} at " f"{os.path.realpath(dest_directory)}")
self.parent_class._generate_std_files(test_result_data.stdout, test_result_data.stderr, dest_directory)
self.parent_class._copy_log_files(test_result_data.log_files, dest_directory)
Expand Down
18 changes: 18 additions & 0 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,24 @@ 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("os.path.isfile")
@patch("os.listdir")
@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_get_list_files(self, mock_local_cluster_logs: Mock, mock_remote_cluster_logs: Mock, mock_test_results_logs: Mock, mock_list_dir: Mock, mock_is_file: Mock, *mock: Any) -> None:
test_recorder = TestRecorder(
"1234",
"integ-test",
"working-directory",
"https://ci.opensearch.org/ci/dbc/integ-test/"
)
mock_list_dir.return_value = ["file1", "file2"]
mock_is_file.return_value = True
mock_dir = MagicMock()
list_files = test_recorder._get_list_files(mock_dir)
self.assertEqual(list_files, ["file1", "file2"])


class TestLocalClusterLogs(unittest.TestCase):

Expand Down

0 comments on commit 5991ed9

Please sign in to comment.