Skip to content

Commit

Permalink
Add more tests for test_recorder
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed May 18, 2023
1 parent 5991ed9 commit 1b5b85f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/test_workflow/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self) -> None:
parser = argparse.ArgumentParser(description="Test an OpenSearch Bundle")
parser.add_argument("test_manifest_path", type=TestArgsPathValidator.validate, help="Specify a test manifest path.")
parser.add_argument("-p", "--paths", nargs='*', action=TestKwargs, default={}, help="Specify paths for OpenSearch and OpenSearch Dashboards.")
# e.g. --base-path https://ci.opensearch.org/ci/dbc/integ-test/2.7.0/7771/linux/x64/tar/ with trailing slash because of the property of urljoin
# e.g. --base-path https://ci.opensearch.org/ci/dbc/integ-test/2.7.0/7771/linux/x64/tar/
parser.add_argument("--base-path", type=str, default="", help="Specify base paths for the integration test logs.")
parser.add_argument("--test-run-id", type=int, help="The unique execution id for the test")
parser.add_argument("--component", type=str, dest="components", nargs='*', help="Test a specific component or components instead of the entire distribution.")
Expand Down
1 change: 1 addition & 0 deletions src/test_workflow/test_recorder/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def save_test_result_data(self, test_result_data: TestResultData) -> None:


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

def __init__(self, parent_class: TestRecorder) -> None:
Expand Down
33 changes: 32 additions & 1 deletion tests/tests_test_workflow/test_recorder/test_test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Any
from unittest.mock import MagicMock, Mock, call, mock_open, patch

from test_workflow.test_recorder.test_recorder import LocalClusterLogs, TestRecorder
from test_workflow.test_recorder.test_recorder import LocalClusterLogs, TestRecorder, TestResultsLogs


@patch("os.makedirs")
Expand Down Expand Up @@ -146,3 +146,34 @@ def test(self) -> None:
logs.save_test_result_data(mock_test_result_data)

mock_parent_class._copy_log_files.assert_called_once_with(mock_test_result_data.log_files, dest_directory)


class TestTestResultsLogs(unittest.TestCase):

def test(self) -> None:
mock_parent_class = MagicMock()

mock_parent_class._create_base_folder_structure.return_value = "test_base"

mock_parent_class._copy_log_files = MagicMock()

logs = TestResultsLogs(mock_parent_class)

mock_test_result_data = MagicMock()

dest_directory = "test_base"

source_file_1 = "stdout.txt"
source_file_2 = "stderr.txt"

mock_test_result_data.log_files = {
source_file_1,
source_file_2
}
mock_test_result_data.component_name = "sql"
mock_test_result_data.component_test_config = "with-security"

logs.save_test_result_data(mock_test_result_data)

mock_parent_class._copy_log_files.assert_called_once_with(mock_test_result_data.log_files, dest_directory)
mock_parent_class._generate_yml.assert_called_once_with(mock_test_result_data, dest_directory)

0 comments on commit 1b5b85f

Please sign in to comment.