Skip to content

Commit 14d70f5

Browse files
author
Cecylia Borek
committed
fix csc apps test
1 parent 1aa5b20 commit 14d70f5

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

tests/searchcommands/test_csc_apps.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,39 @@ def test_eventing_app(self):
6464
self.assertEqual(state.title, "eventing_app")
6565

6666
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+
'''
7075
)
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+
]
7385

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')
78100

79101
def test_generating_app(self):
80102
app_name = "generating_app"
@@ -257,6 +279,22 @@ def test_streaming_app(self):
257279
self.assertTrue(ds[0]["fahrenheit"] == "95.0")
258280
self.assertTrue(len(ds) == 5)
259281

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+
260298

261299
if __name__ == "__main__":
262300
unittest.main()

0 commit comments

Comments
 (0)