Skip to content

Commit dc1ca8e

Browse files
chore: ADDON-80802 Updated the search query for test_requirements_fields
1 parent cd0c088 commit dc1ca8e

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

pytest_splunk_addon/event_ingestors/hec_event_ingestor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def ingest(self, events, thread_count):
9292
"source": event.metadata.get("source", "pytest_splunk_addon:hec:event"),
9393
"event": event.event,
9494
"index": event.metadata.get("index", "main"),
95+
"fields": {"unique_identifier": event.unique_identifier}
9596
}
9697

9798
if event.metadata.get("host_type") in ("plugin", None):

pytest_splunk_addon/fields_tests/test_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def generate_requirements_tests(self):
266266
"escaped_event": escaped_event,
267267
"fields": requirement_fields,
268268
"modinput_params": modinput_params,
269+
"unique_identifier": event.unique_identifier,
269270
},
270271
id=f"sample_name::{event.sample_name}::host::{event.metadata.get('host')}",
271272
)

pytest_splunk_addon/fields_tests/test_templates.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ def test_requirements_fields(
165165
record_property(
166166
"stanza_name", splunk_searchtime_fields_requirements["escaped_event"]
167167
)
168+
record_property(
169+
"stanza_name", splunk_searchtime_fields_requirements["unique_identifier"]
170+
)
168171
record_property("fields", splunk_searchtime_fields_requirements["fields"])
169172
record_property(
170173
"modinput_params", splunk_searchtime_fields_requirements["modinput_params"]
171174
)
172175

173176
escaped_event = splunk_searchtime_fields_requirements["escaped_event"]
177+
unique_identifier = splunk_searchtime_fields_requirements["unique_identifier"]
174178
fields = splunk_searchtime_fields_requirements["fields"]
175179
modinput_params = splunk_searchtime_fields_requirements["modinput_params"]
176180

@@ -185,7 +189,7 @@ def test_requirements_fields(
185189
if param_value is not None:
186190
basic_search += f" {param}={param_value}"
187191

188-
search = f"search {index_list} {basic_search} {escaped_event} | fields *"
192+
search = f"search {index_list} {basic_search} unique_identifier=\"{unique_identifier}\" | fields *"
189193

190194
self.logger.info(f"Executing the search query: {search}")
191195

@@ -225,6 +229,7 @@ def test_requirements_fields(
225229
assert wrong_value_fields == {}, (
226230
f"\nNot all required fields have correct values or some fields are missing in Splunk. Wrong field values:\n{wrong_values_table}"
227231
f"{format_search_query_log(search)}"
232+
f"Test failed for event: {escaped_event}\n"
228233
)
229234

230235
@pytest.mark.splunk_searchtime_fields

pytest_splunk_addon/sample_generation/sample_event.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
import uuid
1617
import re
1718
import logging
1819
from ..index_tests import key_fields
@@ -68,6 +69,7 @@ def __init__(self, event_string, metadata, sample_name, requirement_test_data=No
6869
self.metadata = metadata
6970
self.sample_name = sample_name
7071
self.host_count = 0
72+
self.unique_identifier = str(uuid.uuid4())
7173
self.requirement_test_data = requirement_test_data
7274

7375
def update(self, new_event):

pytest_splunk_addon/sample_generation/sample_xdist_generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def store_events(self, tokenized_events):
131131
"events": [
132132
{
133133
"event": each_event.event,
134+
"unique_identifier": each_event.unique_identifier,
134135
"key_fields": each_event.key_fields,
135136
"time_values": each_event.time_values,
136137
"requirement_test_data": each_event.requirement_test_data,
@@ -141,6 +142,7 @@ def store_events(self, tokenized_events):
141142
tokenized_samples_dict[each_event.sample_name]["events"].append(
142143
{
143144
"event": each_event.event,
145+
"unique_identifier": each_event.unique_identifier,
144146
"key_fields": each_event.key_fields,
145147
"time_values": each_event.time_values,
146148
"requirement_test_data": each_event.requirement_test_data,

0 commit comments

Comments
 (0)