Skip to content

Commit

Permalink
fix: requirement test generation (#893)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dvarasani-crest authored Oct 28, 2024
1 parent 28221b4 commit 8d42cb6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pytest_splunk_addon/cim_tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion pytest_splunk_addon/fields_tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@
<field name="vendor_product" value="Pytest Splunk Addon"/>
</other_mappings>
</event>
</device>
<event code="" name="UnmappedEvent" format="">
<transport type="modinput" sourcetype="test:data:1" source="test_data.1" host="so1" />
<source>
<jira id="" />
<comment>lab</comment>
</source>
<raw><![CDATA[2021-12-31 15:15:30,340+0000 ip=1.1.1.1 tester=admin result=failed]]></raw>
<cim>
</cim>
<other_mappings>
<field name="action" value="failed" />
<field name="status" value="OTHER" />
<field name="app" value="psa" />
<field name="src" value="1.1.1.1" />
<field name="user" value="admin" />
<field name="dest" value="so1" />
<field name="vendor_product" value="Pytest Splunk Addon"/>
</other_mappings>
</event>
</device>
2 changes: 2 additions & 0 deletions tests/e2e/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*',
Expand Down Expand Up @@ -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*",
Expand Down

0 comments on commit 8d42cb6

Please sign in to comment.