@@ -64,17 +64,39 @@ def test_eventing_app(self):
64
64
self .assertEqual (state .title , "eventing_app" )
65
65
66
66
jobs = self .service .jobs
67
- stream = jobs .oneshot (
68
- 'search index="_internal" | head 4000 | eventingcsc status=200 | head 10' ,
69
- output_mode = "json" ,
67
+
68
+ base_search = self ._create_test_data_search (count = 100 )
69
+ full_search = (
70
+ base_search
71
+ + '''
72
+ | eventingcsc status=200
73
+ | head 10
74
+ '''
70
75
)
71
- result = results .JSONResultsReader (stream )
72
- ds = list (result )
76
+ stream = jobs .oneshot (full_search , output_mode = 'json' )
77
+
78
+ reader = results .JSONResultsReader (stream )
79
+ items = list (reader )
80
+
81
+ actual_results = [item for item in items if isinstance (item , dict )]
82
+ informational_messages = [
83
+ item for item in items if isinstance (item , results .Message )
84
+ ]
73
85
74
- self .assertEqual (result .is_preview , False )
75
- self .assertTrue (isinstance (ds [0 ], (dict , results .Message )))
76
- nonmessages = [d for d in ds if isinstance (d , dict )]
77
- self .assertTrue (len (nonmessages ) <= 10 )
86
+ self .assertTrue (len (actual_results ) > 0 )
87
+
88
+ fatal_messages = [
89
+ msg for msg in informational_messages if msg .type in ['FATAL' , 'ERROR' ]
90
+ ]
91
+ self .assertEqual (
92
+ len (fatal_messages ),
93
+ 0 ,
94
+ f"Should not have FATAL/ERROR messages, but got: { [msg .message for msg in fatal_messages ]} " ,
95
+ )
96
+
97
+ first_result = actual_results [0 ]
98
+ self .assertIn ('status' , first_result )
99
+ self .assertEqual (first_result ['status' ], '200' )
78
100
79
101
def test_generating_app (self ):
80
102
app_name = "generating_app"
@@ -257,6 +279,22 @@ def test_streaming_app(self):
257
279
self .assertTrue (ds [0 ]["fahrenheit" ] == "95.0" )
258
280
self .assertTrue (len (ds ) == 5 )
259
281
282
+ def _create_test_data_search (self , count = 100 ):
283
+ """Helper to create deterministic test data using Splunk search commands."""
284
+ return f'''
285
+ | makeresults count={ count }
286
+ | streamstats count as row_num
287
+ | eval _time=_time - (row_num * 60)
288
+ | eval status=case(
289
+ (row_num % 10) < 7, 200,
290
+ (row_num % 10) < 9, 404,
291
+ 1=1, 500
292
+ )
293
+ | eval response_time=100 + ((row_num * 37) % 1000)
294
+ | eval user_id="user" + tostring(row_num % 50)
295
+ | eval _raw=strftime(_time, "%Y-%m-%d %H:%M:%S") + " status=" + tostring(status) + " response_time=" + tostring(response_time) + "ms user=" + user_id
296
+ '''
297
+
260
298
261
299
if __name__ == "__main__" :
262
300
unittest .main ()
0 commit comments