@@ -63,42 +63,36 @@ def test_eventing_app(self):
6363
6464 self .assertEqual (state .title , "eventing_app" )
6565
66- jobs = self .service .jobs
66+ makeresults_count = 20
67+ expected_results_count = 10
68+ expected_status = "200"
6769
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+ search_query = f"""
71+ | makeresults count={ makeresults_count }
72+ | streamstats count as row_num
73+ | eval status=case(
74+ (row_num % 2) == 1, 200,
75+ 1=1, 500
7576 )
76- stream = jobs .oneshot (full_search , output_mode = "json" )
77+ | eventingcsc status={ expected_status }
78+ """
79+ stream = self .service .jobs .oneshot (search_query , output_mode = "json" )
7780
78- reader = results .JSONResultsReader (stream )
79- items = list (reader )
81+ results_reader = results .JSONResultsReader (stream )
82+ items = list (results_reader )
8083
81- self .assertEqual ( reader .is_preview , False )
84+ self .assertFalse ( results_reader .is_preview )
8285
83- actual_results = [ item for item in items if isinstance ( item , dict )]
84- informational_messages = [
85- item for item in items if isinstance (item , results .Message )
86+ # filter out informational messages and keep only search results
87+ actual_results = [
88+ item for item in items if not isinstance (item , results .Message )
8689 ]
8790
88- self .assertTrue (len (actual_results ) > 0 )
89-
90- fatal_messages = [
91- msg for msg in informational_messages if msg .type in ["FATAL" , "ERROR" ]
92- ]
93- self .assertEqual (
94- len (fatal_messages ),
95- 0 ,
96- f"Should not have FATAL/ERROR messages, but got: { [msg .message for msg in fatal_messages ]} " ,
97- )
91+ self .assertTrue (len (actual_results ) == expected_results_count )
9892
9993 for res in actual_results :
10094 self .assertIn ("status" , res )
101- self .assertEqual (res ["status" ], "200" )
95+ self .assertEqual (res ["status" ], expected_status )
10296
10397 def test_generating_app (self ):
10498 app_name = "generating_app"
@@ -281,22 +275,6 @@ def test_streaming_app(self):
281275 self .assertTrue (ds [0 ]["fahrenheit" ] == "95.0" )
282276 self .assertTrue (len (ds ) == 5 )
283277
284- def _create_test_data_search (self , count = 100 ):
285- """Helper to create deterministic test data using Splunk search commands."""
286- return f"""
287- | makeresults count={ count }
288- | streamstats count as row_num
289- | eval _time=_time - (row_num * 60)
290- | eval status=case(
291- (row_num % 10) < 7, 200,
292- (row_num % 10) < 9, 404,
293- 1=1, 500
294- )
295- | eval response_time=100 + ((row_num * 37) % 1000)
296- | eval user_id="user" + tostring(row_num % 50)
297- | eval _raw=strftime(_time, "%Y-%m-%d %H:%M:%S") + " status=" + tostring(status) + " response_time=" + tostring(response_time) + "ms user=" + user_id
298- """
299-
300278
301279if __name__ == "__main__" :
302280 unittest .main ()
0 commit comments