Skip to content

Commit 91f22e9

Browse files
chore: ADDON-80802 Updated the working of test_datamodels test using uuid
1 parent 83ad20f commit 91f22e9

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

pytest_splunk_addon/event_ingestors/hec_event_ingestor.py

Lines changed: 4 additions & 2 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 json
1617
from .base_event_ingestor import EventIngestor
1718
import requests
1819
from time import time, mktime
@@ -117,20 +118,21 @@ def ingest(self, events, thread_count):
117118

118119
def __ingest(self, data):
119120
try:
121+
batch_data = "\n".join(json.dumps(obj) for obj in data)
120122
LOGGER.info(
121123
"Making a HEC event request with the following params:\nhec_uri:{}\nheaders:{}".format(
122124
str(self.hec_uri), str(self.session_headers)
123125
)
124126
)
125127
LOGGER.debug(
126128
"Creating the following sample event to be ingested via HEC event endoipnt:{}".format(
127-
str(data)
129+
str(batch_data)
128130
)
129131
)
130132
response = requests.post( # nosemgrep: splunk.disabled-cert-validation
131133
"{}/{}".format(self.hec_uri, "event"),
132134
auth=None,
133-
json=data,
135+
data=batch_data,
134136
headers=self.session_headers,
135137
verify=False,
136138
)

pytest_splunk_addon/fields_tests/test_generator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,14 @@ def generate_requirements_datamodels_tests(self):
190190
datamodel.replace(" ", "_").replace(":", "_")
191191
for datamodel in datamodels
192192
]
193-
yield pytest.param(
194-
{
193+
sample_event = {
195194
"datamodels": datamodels,
196195
"stanza": escaped_event,
197-
},
196+
}
197+
if event.metadata["ingest_with_uuid"] == "true":
198+
sample_event["unique_identifier"] = event.unique_identifier
199+
yield pytest.param(
200+
sample_event,
198201
id=f"{'-'.join(datamodels)}::sample_name::{event.sample_name}::host::{event.metadata.get('host')}",
199202
)
200203

pytest_splunk_addon/fields_tests/test_templates.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,6 @@ def test_datamodels(
403403
"""
404404
esacaped_event = splunk_searchtime_fields_datamodels["stanza"]
405405
datamodels = splunk_searchtime_fields_datamodels["datamodels"]
406-
self.logger.info(
407-
f"Testing for tag {datamodels} with tag_query {esacaped_event}"
408-
)
409406

410407
record_property("Event_with", esacaped_event)
411408
record_property("datamodels", datamodels)
@@ -415,7 +412,23 @@ def test_datamodels(
415412
+ " OR index=".join(splunk_search_util.search_index.split(","))
416413
+ ")"
417414
)
418-
search = f"search {index_list} {esacaped_event} | fields *"
415+
416+
if splunk_searchtime_fields_datamodels.get("unique_identifier"):
417+
record_property(
418+
"stanza_name", splunk_searchtime_fields_datamodels["unique_identifier"]
419+
)
420+
unique_identifier = splunk_searchtime_fields_datamodels["unique_identifier"]
421+
422+
self.logger.info(
423+
f"Testing for tag {datamodels} with unique_identifier=\"{unique_identifier}\""
424+
)
425+
426+
search = f"search {index_list} unique_identifier=\"{unique_identifier}\" | fields *"
427+
else:
428+
self.logger.info(
429+
f"Testing for tag {datamodels} with tag_query {esacaped_event}"
430+
)
431+
search = f"search {index_list} {esacaped_event} | fields *"
419432

420433
self.logger.info(f"Search: {search}")
421434

0 commit comments

Comments
 (0)