Skip to content

Commit ccf4e8e

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

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

tests/searchcommands/test_csc_apps.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,41 @@ 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+
self.assertEqual(reader.is_preview, False)
7382

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)
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+
]
87+
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+
)
98+
99+
for res in actual_results:
100+
self.assertIn("status", res)
101+
self.assertEqual(res["status"], "200")
78102

79103
def test_generating_app(self):
80104
app_name = "generating_app"
@@ -257,6 +281,22 @@ def test_streaming_app(self):
257281
self.assertTrue(ds[0]["fahrenheit"] == "95.0")
258282
self.assertTrue(len(ds) == 5)
259283

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

261301
if __name__ == "__main__":
262302
unittest.main()

0 commit comments

Comments
 (0)