Skip to content

Commit

Permalink
Add more tests to meet the coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed Aug 10, 2023
1 parent f5e7109 commit c6c5715
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/report_workflow/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#### Generate test-report manifest for each test.
The input requires a mandatory `test-manifest-path`, `--artifact-paths`, `--base-path`, `--test-type` and `--test-run-id`, optional `--output-path` and `--component` to automatically generate the test-report manifest after testing.
As the name specifies, the test report workflow helps to automatically generate a consolidated report of the tests run at distribution level along with commands to reproduce the error and associated failures.

*Usage*
```
Expand All @@ -18,7 +18,7 @@ The following options are available.
| --base-path <required> | Base paths of testing logs. |
| --test-type <required> | Type of tests report generates on. |
| --output-path <optional> | Specify the path location for the test-report manifest. |
| --test-run-id <required> | Specify the unique execution id for the test. |
| --test-run-id <required> | Specify the unique execution id that matches the id of the test. |
| --component <optional> | Specify a specific component or components instead of the entire distribution. |
| --verbose <optional> | Show more verbose output. |

24 changes: 24 additions & 0 deletions tests/tests_report_workflow/test_test_report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from manifests.test_manifest import TestManifest
from report_workflow.test_report_runner import TestReportRunner
from system.temporary_directory import TemporaryDirectory


class TestTestReportRunner(unittest.TestCase):
Expand Down Expand Up @@ -41,6 +42,29 @@ def test_runner_init(self, report_args_mock: MagicMock, test_manifest_mock: Magi
self.assertEqual(test_run_runner.test_type, "integ-test")
self.assertEqual(test_run_runner.test_manifest_path, self.TEST_MANIFEST_PATH)

@patch("yaml.safe_load")
@patch("urllib.request.urlopen")
@patch("validators.url")
@patch("report_workflow.report_args.ReportArgs")
def test_generate_file(self, report_args_mock: MagicMock, validators_mock: MagicMock, urlopen_mock: MagicMock, yaml_safe_load_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_PATH
report_args_mock.artifact_paths = {"opensearch": "foo/bar"}
report_args_mock.test_run_id = 123
report_args_mock.base_path = "https://ci.opensearch.org/ci/dbc/mock"
report_args_mock.test_type = "integ-test"

validators_mock.return_value = True
yaml_safe_load_mock.return_value = {"test_result": "PASS"}
urlopen_mock.return_value = MagicMock()

test_run_runner = TestReportRunner(report_args_mock, self.TEST_MANIFEST)
test_run_runner_data = test_run_runner.update_data()

with TemporaryDirectory() as path:
output_path = os.path.join(path.name, "test-report.yml")
test_run_runner.generate_report(test_run_runner_data, path.name)
self.assertTrue(os.path.isfile(output_path))

@patch("report_workflow.report_args.ReportArgs")
@patch("manifests.test_manifest.TestManifest")
def test_runner_update_test_run_data_local(self, report_args_mock: MagicMock, test_manifest_mock: MagicMock) -> None:
Expand Down

0 comments on commit c6c5715

Please sign in to comment.