|
12 | 12 | import json |
13 | 13 | import logging |
14 | 14 | import os |
| 15 | +import re |
15 | 16 | import time |
16 | 17 | import requests |
17 | 18 | import pytest |
@@ -136,17 +137,28 @@ def test_log_content_matches(self): |
136 | 137 | print("Waiting for log ingestion...") |
137 | 138 | time.sleep(240) |
138 | 139 |
|
139 | | - query = f"env_id:{self.env_id} AND message:*Content*validation*" |
| 140 | + query = f"env_id:{self.env_id}" |
140 | 141 | response = fetch_logs(self.api_key, query) |
141 | 142 |
|
142 | | - total = response.get("hits", {}).get("total", 0) |
143 | | - if total == 0: |
144 | | - pytest.fail("Test log not found") |
| 143 | + hits = response.get("hits", {}).get("hits", []) |
| 144 | + if not hits: |
| 145 | + pytest.fail("No logs found for env_id") |
| 146 | + |
| 147 | + # Find the log with matching message using regex |
| 148 | + pattern = re.compile(r"Content\s+validation\s+test") |
| 149 | + matching_log = None |
| 150 | + for hit in hits: |
| 151 | + source = hit.get("_source", {}) |
| 152 | + message = source.get("message", "") |
| 153 | + if pattern.search(message): |
| 154 | + matching_log = source |
| 155 | + break |
| 156 | + |
| 157 | + if not matching_log: |
| 158 | + pytest.fail("Test log with 'Content validation test' not found in message field") |
145 | 159 |
|
146 | | - hit = response["hits"]["hits"][0]["_source"] |
147 | | - assert "Content validation test" in hit.get("message", ""), "Message content mismatch" |
148 | | - assert hit.get("env_id") == self.env_id, "env_id mismatch" |
149 | | - assert hit.get("test_source") == "python-handler-e2e", "test_source mismatch" |
| 160 | + assert matching_log.get("env_id") == self.env_id, "env_id mismatch" |
| 161 | + assert matching_log.get("test_source") == "python-handler-e2e", "test_source mismatch" |
150 | 162 |
|
151 | 163 | print("✅ Log content matches expected values") |
152 | 164 |
|
|
0 commit comments