Skip to content

Commit 888bf57

Browse files
committed
test(opensearch): cover multi-source, 'search' keyword, ws around =
Signed-off-by: Azorji Kelechi Oliver <kelechioliver96@gmail.com>
1 parent b890fec commit 888bf57

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

opensearch/src/queries/opensearch-log-query/get-opensearch-log-data.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,35 @@ describe('buildBoundedPPL', () => {
217217
"source=logs-* | where `@timestamp` >= '2025-01-01T00:00:00.000Z' and `@timestamp` <= '2025-01-01T01:00:00.000Z'"
218218
);
219219
});
220+
221+
it('preserves a comma-separated multi-source clause', () => {
222+
const q = buildBoundedPPL('source=logs-2026.04,logs-2026.05 | head 10', start, end);
223+
expect(q.startsWith('source=logs-2026.04,logs-2026.05 | where `@timestamp`')).toBe(true);
224+
expect(q).toContain('| head 10');
225+
});
226+
227+
it("preserves the optional 'search' keyword in front of source=", () => {
228+
const q = buildBoundedPPL('search source=logs-* | head 10', start, end);
229+
expect(q.startsWith('search source=logs-* | where `@timestamp`')).toBe(true);
230+
expect(q).toContain('| head 10');
231+
});
232+
233+
it('preserves whitespace around the source equals sign', () => {
234+
const q = buildBoundedPPL('source = logs-* | head 10', start, end);
235+
expect(q.startsWith('source = logs-* | where `@timestamp`')).toBe(true);
236+
expect(q).toContain('| head 10');
237+
});
238+
239+
it('keeps the user time filter intact when one is already present (PPL ANDs them, both run before stats)', () => {
240+
const q = buildBoundedPPL(
241+
"source=logs-* | where `@timestamp` >= '2024-12-31T00:00:00Z' | stats count() by service",
242+
start,
243+
end
244+
);
245+
expect(q).toBe(
246+
"source=logs-* | where `@timestamp` >= '2025-01-01T00:00:00.000Z' and `@timestamp` <= '2025-01-01T01:00:00.000Z' | where `@timestamp` >= '2024-12-31T00:00:00Z' | stats count() by service"
247+
);
248+
});
220249
});
221250

222251
describe('convertPPLToLogs', () => {

0 commit comments

Comments
 (0)