Skip to content

Commit 6f4d2c3

Browse files
author
Cecylia Borek
committed
test using sythetic data
1 parent 84b48ad commit 6f4d2c3

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

tests/searchcommands/test_csc_apps.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,20 @@ def test_eventing_app(self):
6969

7070
jobs = self.service.jobs
7171

72-
test_index_stream = jobs.oneshot(
73-
'search index="_internal" | head 10', output_mode='json'
72+
base_search = self._create_test_data_search(count=100)
73+
full_search = (
74+
base_search
75+
+ '''
76+
| eventingcsc status=200
77+
| head 10
78+
'''
7479
)
75-
test_reader = results.JSONResultsReader(test_index_stream)
76-
test_items = list(test_reader)
7780

78-
print("DEBUG: Test items from _internal index stream:")
79-
for item in test_items:
80-
print(item)
81+
stream = jobs.oneshot(full_search, output_mode='json')
8182

82-
stream = jobs.oneshot(
83-
'search index="_internal" | fields status | head 4000 | eventingcsc status=200 | head 10',
84-
output_mode='json',
85-
)
86-
8783
reader = results.JSONResultsReader(stream)
8884
items = list(reader)
8985

90-
print("DEBUG: Items from eventingcsc command:")
91-
for item in items:
92-
print(item)
93-
9486
actual_results = [item for item in items if isinstance(item, dict)]
9587
informational_messages = [
9688
item for item in items if isinstance(item, results.Message)
@@ -332,6 +324,22 @@ def test_streaming_app(self):
332324
self.assertTrue(ds[0]["fahrenheit"] == "95.0")
333325
self.assertTrue(len(ds) == 5)
334326

327+
def _create_test_data_search(self, count=100):
328+
"""Helper to create deterministic test data using Splunk search commands."""
329+
return f'''
330+
| makeresults count={count}
331+
| streamstats count as row_num
332+
| eval _time=_time - (row_num * 60)
333+
| eval status=case(
334+
(row_num % 10) < 7, 200,
335+
(row_num % 10) < 9, 404,
336+
1=1, 500
337+
)
338+
| eval response_time=100 + ((row_num * 37) % 1000)
339+
| eval user_id="user" + tostring(row_num % 50)
340+
| eval _raw=strftime(_time, "%Y-%m-%d %H:%M:%S") + " status=" + tostring(status) + " response_time=" + tostring(response_time) + "ms user=" + user_id
341+
'''
342+
335343

336344
if __name__ == "__main__":
337345
unittest.main()

0 commit comments

Comments
 (0)