Skip to content

Commit 8d42cb6

Browse files
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.
1 parent 28221b4 commit 8d42cb6

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

pytest_splunk_addon/cim_tests/test_generator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ def generate_recommended_fields_tests(self):
268268
3. yield object with datamodel, dataset, cim_version and list of fields
269269
"""
270270
for event in self.tokenized_events:
271-
if not event.requirement_test_data:
271+
if (
272+
not event.requirement_test_data
273+
or event.requirement_test_data.keys() == {"other_fields"}
274+
):
272275
continue
273276
for _, datamodels in event.requirement_test_data["datamodels"].items():
274277
if type(datamodels) is not list:

pytest_splunk_addon/fields_tests/test_generator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ def generate_requirements_datamodels_tests(self):
160160
pytest.params for the test templates
161161
"""
162162
for event in self.tokenized_events:
163-
if not event.requirement_test_data:
163+
if (
164+
not event.requirement_test_data
165+
or event.requirement_test_data.keys() == {"other_fields"}
166+
):
164167
continue
165168
if event.metadata.get("input_type", "").startswith("syslog"):
166169
stripped_event = xml_event_parser.strip_syslog_header(event.event)

tests/e2e/addons/TA_transition_from_req/samples/sample_modinput.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,23 @@
3030
<field name="vendor_product" value="Pytest Splunk Addon"/>
3131
</other_mappings>
3232
</event>
33-
</device>
33+
<event code="" name="UnmappedEvent" format="">
34+
<transport type="modinput" sourcetype="test:data:1" source="test_data.1" host="so1" />
35+
<source>
36+
<jira id="" />
37+
<comment>lab</comment>
38+
</source>
39+
<raw><![CDATA[2021-12-31 15:15:30,340+0000 ip=1.1.1.1 tester=admin result=failed]]></raw>
40+
<cim>
41+
</cim>
42+
<other_mappings>
43+
<field name="action" value="failed" />
44+
<field name="status" value="OTHER" />
45+
<field name="app" value="psa" />
46+
<field name="src" value="1.1.1.1" />
47+
<field name="user" value="admin" />
48+
<field name="dest" value="so1" />
49+
<field name="vendor_product" value="Pytest Splunk Addon"/>
50+
</other_mappings>
51+
</event>
52+
</device>

tests/e2e/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@
771771
"*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*",
772772
"*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*",
773773
"*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*",
774+
"*test_splunk_app_req.py::Test_App::test_indextime_time[test:data:1::* PASSED*",
774775
"*test_splunk_app_req.py::Test_App::test_indextime_line_breaker[test:data:1::sample_modinput.xml* PASSED*",
775776
'*test_splunk_app_req.py::Test_App::test_cim_required_fields[eventtype="test_auth"::Authentication* PASSED*',
776777
'*test_splunk_app_req.py::Test_App::test_cim_required_fields[eventtype="test_auth"::Authentication::action* PASSED*',
@@ -802,6 +803,7 @@
802803
"*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1-4* PASSED*",
803804
"*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1-5* PASSED*",
804805
"*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1-6* PASSED*",
806+
"*test_splunk_app_req.py::Test_App::test_requirements_fields[sample_name::sample_modinput.xml::host::so1* PASSED*",
805807
"*test_splunk_app_req.py::Test_App::test_props_fields_no_dash_not_empty[test:data:1::field::action* PASSED*",
806808
"*test_splunk_app_req.py::Test_App::test_props_fields_no_dash_not_empty[test:data:1::field::app* PASSED*",
807809
"*test_splunk_app_req.py::Test_App::test_props_fields_no_dash_not_empty[test:data:1::field::dest* PASSED*",

0 commit comments

Comments
 (0)