From ebe6cef15008e8b470e69db2eafdfe2b0a9929fd Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 11 Oct 2024 08:35:03 +0200 Subject: [PATCH 1/4] [ES|QL] Updates the validation tests --- .../esql_validation_meta_tests.json | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json index 1eb861168a13a..1327ed4af98bd 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json +++ b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json @@ -9836,22 +9836,30 @@ }, { "query": "fRoM remote-*:indexes*", - "error": [], + "error": [ + "Unknown index [remote-*:indexes*]" + ], "warning": [] }, { "query": "fRoM remote-*:indexes", - "error": [], + "error": [ + "Unknown index [remote-*:indexes]" + ], "warning": [] }, { "query": "fRoM remote-ccs:indexes", - "error": [], + "error": [ + "Unknown index [remote-ccs:indexes]" + ], "warning": [] }, { "query": "fRoM a_index, remote-ccs:indexes", - "error": [], + "error": [ + "Unknown index [remote-ccs:indexes]" + ], "warning": [] }, { @@ -9988,14 +9996,18 @@ }, { "query": "from remote-ccs:indexes [METADATA _id]", - "error": [], + "error": [ + "Unknown index [remote-ccs:indexes]" + ], "warning": [ "Square brackets '[]' need to be removed from FROM METADATA declaration" ] }, { "query": "from *:indexes [METADATA _id]", - "error": [], + "error": [ + "Unknown index [*:indexes]" + ], "warning": [ "Square brackets '[]' need to be removed from FROM METADATA declaration" ] @@ -10040,12 +10052,16 @@ }, { "query": "from remote-ccs:indexes METADATA _id", - "error": [], + "error": [ + "Unknown index [remote-ccs:indexes]" + ], "warning": [] }, { "query": "from *:indexes METADATA _id", - "error": [], + "error": [ + "Unknown index [*:indexes]" + ], "warning": [] }, { From 87a1bbd93e35d753a30c8ed2f28d488768731500 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Mon, 14 Oct 2024 09:07:05 +0200 Subject: [PATCH 2/4] Create own validation test --- .../test_suites/validation.command.ccs.ts | 60 +++++++++++++++++++ .../test_suites/validation.command.from.ts | 16 ----- .../__tests__/validation.command.ccs.test.ts | 13 ++++ .../esql_validation_meta_tests.json | 60 ------------------- 4 files changed, 73 insertions(+), 76 deletions(-) create mode 100644 packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts create mode 100644 packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts new file mode 100644 index 0000000000000..a8c6684533546 --- /dev/null +++ b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts @@ -0,0 +1,60 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import * as helpers from '../helpers'; + +export const validationCCSCommandTestSuite = (setup: helpers.Setup) => { + describe('validation', () => { + describe('from command', () => { + describe('FROM [ METADATA ]', () => { + describe('... ...', () => { + test('display errors on unknown indices', async () => { + const { expectErrors } = await setup(); + await expectErrors('fRoM remote-*:indexes*', ['Unknown index [remote-*:indexes*]']); + await expectErrors('fRoM remote-*:indexes', ['Unknown index [remote-*:indexes]']); + await expectErrors('fRoM remote-ccs:indexes', ['Unknown index [remote-ccs:indexes]']); + await expectErrors('fRoM a_index, remote-ccs:indexes', [ + 'Unknown index [remote-ccs:indexes]', + ]); + }); + }); + + describe('... METADATA ', () => { + for (const isWrapped of [true, false]) { + function setWrapping(option: string) { + return isWrapped ? `[${option}]` : option; + } + + function addBracketsWarning() { + return isWrapped + ? ["Square brackets '[]' need to be removed from FROM METADATA declaration"] + : []; + } + + describe(`wrapped = ${isWrapped}`, () => { + test('no errors on correct usage, waning on square brackets', async () => { + const { expectErrors } = await setup(); + await expectErrors( + `from remote-ccs:indexes ${setWrapping('METADATA _id')}`, + ['Unknown index [remote-ccs:indexes]'], + addBracketsWarning() + ); + await expectErrors( + `from *:indexes ${setWrapping('METADATA _id')}`, + ['Unknown index [*:indexes]'], + addBracketsWarning() + ); + }); + }); + } + }); + }); + }); + }); +}; diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.from.ts b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.from.ts index e3589bb8da643..3da63848168a3 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.from.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.from.ts @@ -56,12 +56,6 @@ export const validationFromCommandTestSuite = (setup: helpers.Setup) => { await expectErrors('fRoM in*ex', []); await expectErrors('fRoM ind*ex', []); await expectErrors('fRoM *,-.*', []); - await expectErrors('fRoM remote-*:indexes*', ['Unknown index [remote-*:indexes*]']); - await expectErrors('fRoM remote-*:indexes', ['Unknown index [remote-*:indexes]']); - await expectErrors('fRoM remote-ccs:indexes', ['Unknown index [remote-ccs:indexes]']); - await expectErrors('fRoM a_index, remote-ccs:indexes', [ - 'Unknown index [remote-ccs:indexes]', - ]); await expectErrors('fRoM .secret_index', []); await expectErrors('from my-index', []); }); @@ -151,16 +145,6 @@ export const validationFromCommandTestSuite = (setup: helpers.Setup) => { [], addBracketsWarning() ); - await expectErrors( - `from remote-ccs:indexes ${setWrapping('METADATA _id')}`, - ['Unknown index [remote-ccs:indexes]'], - addBracketsWarning() - ); - await expectErrors( - `from *:indexes ${setWrapping('METADATA _id')}`, - ['Unknown index [*:indexes]'], - addBracketsWarning() - ); }); test('validates fields', async () => { diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts new file mode 100644 index 0000000000000..691a7444fdff1 --- /dev/null +++ b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import * as helpers from './helpers'; +import { validationCCSCommandTestSuite } from './test_suites/validation.command.ccs'; + +validationCCSCommandTestSuite(helpers.setup); diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json index 1327ed4af98bd..43a42f0270b74 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json +++ b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json @@ -9834,34 +9834,6 @@ "error": [], "warning": [] }, - { - "query": "fRoM remote-*:indexes*", - "error": [ - "Unknown index [remote-*:indexes*]" - ], - "warning": [] - }, - { - "query": "fRoM remote-*:indexes", - "error": [ - "Unknown index [remote-*:indexes]" - ], - "warning": [] - }, - { - "query": "fRoM remote-ccs:indexes", - "error": [ - "Unknown index [remote-ccs:indexes]" - ], - "warning": [] - }, - { - "query": "fRoM a_index, remote-ccs:indexes", - "error": [ - "Unknown index [remote-ccs:indexes]" - ], - "warning": [] - }, { "query": "fRoM .secret_index", "error": [], @@ -9994,24 +9966,6 @@ "Square brackets '[]' need to be removed from FROM METADATA declaration" ] }, - { - "query": "from remote-ccs:indexes [METADATA _id]", - "error": [ - "Unknown index [remote-ccs:indexes]" - ], - "warning": [ - "Square brackets '[]' need to be removed from FROM METADATA declaration" - ] - }, - { - "query": "from *:indexes [METADATA _id]", - "error": [ - "Unknown index [*:indexes]" - ], - "warning": [ - "Square brackets '[]' need to be removed from FROM METADATA declaration" - ] - }, { "query": "from index [METADATA _id, _source2]", "error": [ @@ -10050,20 +10004,6 @@ "error": [], "warning": [] }, - { - "query": "from remote-ccs:indexes METADATA _id", - "error": [ - "Unknown index [remote-ccs:indexes]" - ], - "warning": [] - }, - { - "query": "from *:indexes METADATA _id", - "error": [ - "Unknown index [*:indexes]" - ], - "warning": [] - }, { "query": "from index METADATA _id, _source2", "error": [ From 6b937011ca6431e84d6286480eae9a8e9341894e Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Mon, 14 Oct 2024 16:34:44 +0200 Subject: [PATCH 3/4] Change to not run them as integration tests --- .../test_suites/validation.command.ccs.ts | 60 ------------------- .../__tests__/validation.command.ccs.test.ts | 50 +++++++++++++++- 2 files changed, 47 insertions(+), 63 deletions(-) delete mode 100644 packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts deleted file mode 100644 index a8c6684533546..0000000000000 --- a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/test_suites/validation.command.ccs.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import * as helpers from '../helpers'; - -export const validationCCSCommandTestSuite = (setup: helpers.Setup) => { - describe('validation', () => { - describe('from command', () => { - describe('FROM [ METADATA ]', () => { - describe('... ...', () => { - test('display errors on unknown indices', async () => { - const { expectErrors } = await setup(); - await expectErrors('fRoM remote-*:indexes*', ['Unknown index [remote-*:indexes*]']); - await expectErrors('fRoM remote-*:indexes', ['Unknown index [remote-*:indexes]']); - await expectErrors('fRoM remote-ccs:indexes', ['Unknown index [remote-ccs:indexes]']); - await expectErrors('fRoM a_index, remote-ccs:indexes', [ - 'Unknown index [remote-ccs:indexes]', - ]); - }); - }); - - describe('... METADATA ', () => { - for (const isWrapped of [true, false]) { - function setWrapping(option: string) { - return isWrapped ? `[${option}]` : option; - } - - function addBracketsWarning() { - return isWrapped - ? ["Square brackets '[]' need to be removed from FROM METADATA declaration"] - : []; - } - - describe(`wrapped = ${isWrapped}`, () => { - test('no errors on correct usage, waning on square brackets', async () => { - const { expectErrors } = await setup(); - await expectErrors( - `from remote-ccs:indexes ${setWrapping('METADATA _id')}`, - ['Unknown index [remote-ccs:indexes]'], - addBracketsWarning() - ); - await expectErrors( - `from *:indexes ${setWrapping('METADATA _id')}`, - ['Unknown index [*:indexes]'], - addBracketsWarning() - ); - }); - }); - } - }); - }); - }); - }); -}; diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts index 691a7444fdff1..5cdb83be618d1 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts @@ -6,8 +6,52 @@ * your election, the "Elastic License 2.0", the "GNU Affero General Public * License v3.0 only", or the "Server Side Public License, v 1". */ +import { setup } from './helpers'; -import * as helpers from './helpers'; -import { validationCCSCommandTestSuite } from './test_suites/validation.command.ccs'; +describe('validation', () => { + describe('from command', () => { + describe('FROM [ METADATA ]', () => { + describe('... ...', () => { + test('display errors on unknown indices', async () => { + const { expectErrors } = await setup(); + await expectErrors('fRoM remote-*:indexes*', ['Unknown index [remote-*:indexes*]']); + await expectErrors('fRoM remote-*:indexes', ['Unknown index [remote-*:indexes]']); + await expectErrors('fRoM remote-ccs:indexes', ['Unknown index [remote-ccs:indexes]']); + await expectErrors('fRoM a_index, remote-ccs:indexes', [ + 'Unknown index [remote-ccs:indexes]', + ]); + }); + }); -validationCCSCommandTestSuite(helpers.setup); + describe('... METADATA ', () => { + for (const isWrapped of [true, false]) { + function setWrapping(option: string) { + return isWrapped ? `[${option}]` : option; + } + + function addBracketsWarning() { + return isWrapped + ? ["Square brackets '[]' need to be removed from FROM METADATA declaration"] + : []; + } + + describe(`wrapped = ${isWrapped}`, () => { + test('no errors on correct usage, waning on square brackets', async () => { + const { expectErrors } = await setup(); + await expectErrors( + `from remote-ccs:indexes ${setWrapping('METADATA _id')}`, + ['Unknown index [remote-ccs:indexes]'], + addBracketsWarning() + ); + await expectErrors( + `from *:indexes ${setWrapping('METADATA _id')}`, + ['Unknown index [*:indexes]'], + addBracketsWarning() + ); + }); + }); + } + }); + }); + }); +}); From 96df9767e9d83f6fbda9cd9dfe729b69794fcf7e Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Mon, 14 Oct 2024 16:43:16 +0200 Subject: [PATCH 4/4] Rename file --- .../{validation.command.ccs.test.ts => validation.ccs.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/kbn-esql-validation-autocomplete/src/validation/__tests__/{validation.command.ccs.test.ts => validation.ccs.test.ts} (100%) diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts b/packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.ccs.test.ts similarity index 100% rename from packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.command.ccs.test.ts rename to packages/kbn-esql-validation-autocomplete/src/validation/__tests__/validation.ccs.test.ts