From 8d42cb6cced14b63592c634e13fa616b9aa2fdda Mon Sep 17 00:00:00 2001 From: dvarasani-crest <151819886+dvarasani-crest@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:58:38 +0530 Subject: [PATCH] fix: requirement test generation (#893) Fix the issue with requirement test generation. - Requirement test generation for "test_cim_fields_recommended" was failing for the sample event with only `other_mappings` and no cim mapping attached. Updated e2e tests to cover this scenario as well. --- .../cim_tests/test_generator.py | 5 ++++- .../fields_tests/test_generator.py | 5 ++++- .../samples/sample_modinput.xml | 21 ++++++++++++++++++- tests/e2e/constants.py | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/pytest_splunk_addon/cim_tests/test_generator.py b/pytest_splunk_addon/cim_tests/test_generator.py index 7e0e2194..6c58f899 100644 --- a/pytest_splunk_addon/cim_tests/test_generator.py +++ b/pytest_splunk_addon/cim_tests/test_generator.py @@ -268,7 +268,10 @@ def generate_recommended_fields_tests(self): 3. yield object with datamodel, dataset, cim_version and list of fields """ for event in self.tokenized_events: - if not event.requirement_test_data: + if ( + not event.requirement_test_data + or event.requirement_test_data.keys() == {"other_fields"} + ): continue for _, datamodels in event.requirement_test_data["datamodels"].items(): if type(datamodels) is not list: diff --git a/pytest_splunk_addon/fields_tests/test_generator.py b/pytest_splunk_addon/fields_tests/test_generator.py index 68d81029..8ca22c60 100644 --- a/pytest_splunk_addon/fields_tests/test_generator.py +++ b/pytest_splunk_addon/fields_tests/test_generator.py @@ -160,7 +160,10 @@ def generate_requirements_datamodels_tests(self): pytest.params for the test templates """ for event in self.tokenized_events: - if not event.requirement_test_data: + if ( + not event.requirement_test_data + or event.requirement_test_data.keys() == {"other_fields"} + ): continue if event.metadata.get("input_type", "").startswith("syslog"): stripped_event = xml_event_parser.strip_syslog_header(event.event) diff --git a/tests/e2e/addons/TA_transition_from_req/samples/sample_modinput.xml b/tests/e2e/addons/TA_transition_from_req/samples/sample_modinput.xml index 1a1b2369..1b7d89ed 100644 --- a/tests/e2e/addons/TA_transition_from_req/samples/sample_modinput.xml +++ b/tests/e2e/addons/TA_transition_from_req/samples/sample_modinput.xml @@ -30,4 +30,23 @@ - \ No newline at end of file + + + + + lab + + + + + + + + + + + + + + + diff --git a/tests/e2e/constants.py b/tests/e2e/constants.py index 403c1910..6e6579da 100644 --- a/tests/e2e/constants.py +++ b/tests/e2e/constants.py @@ -771,6 +771,7 @@ "*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*", "*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*", "*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*", + "*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*", "*test_splunk_app_req.py::Test_App::test_indextime_line_breaker[test:data:1::sample_modinput.xml* PASSED*", '*test_splunk_app_req.py::Test_App::test_cim_required_fields[eventtype="test_auth"::Authentication* PASSED*', '*test_splunk_app_req.py::Test_App::test_cim_required_fields[eventtype="test_auth"::Authentication::action* PASSED*', @@ -802,6 +803,7 @@ "*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1-4* PASSED*", "*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1-5* PASSED*", "*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1-6* PASSED*", + "*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1* PASSED*", "*test_splunk_app_req.py::Test_App::test_props_fields_no_dash_not_empty[test:data:1::field::action* PASSED*", "*test_splunk_app_req.py::Test_App::test_props_fields_no_dash_not_empty[test:data:1::field::app* PASSED*", "*test_splunk_app_req.py::Test_App::test_props_fields_no_dash_not_empty[test:data:1::field::dest* PASSED*",