From ed4e84defad3c1d26bf93726980c1edeeb12a760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20Loix?= Date: Thu, 26 Nov 2020 09:55:44 +0100 Subject: [PATCH] Add Api integration tests for the ES error parser --- .../management/index_management/templates.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/x-pack/test/api_integration/apis/management/index_management/templates.js b/x-pack/test/api_integration/apis/management/index_management/templates.js index 8d491e6a135ea..dd5dac5626041 100644 --- a/x-pack/test/api_integration/apis/management/index_management/templates.js +++ b/x-pack/test/api_integration/apis/management/index_management/templates.js @@ -191,6 +191,26 @@ export default function ({ getService }) { '[request body.indexPatterns]: expected value of type [array] ' ); }); + + it('should parse the ES error and return the cause', async () => { + const templateName = `template-${getRandomString()}`; + const payload = getTemplatePayload(templateName, [getRandomString()]); + const runtime = { + myRuntimeField: { + type: 'boolean', + script: { + source: 'emit("hello with error', // error in script + }, + }, + }; + payload.template.mappings = { ...payload.template.mappings, runtime }; + const { body } = await createTemplate(payload).expect(400); + + expect(body.attributes).an('object'); + expect(body.attributes.message).contain('template after composition is invalid'); + // one of the item of the cause array should point to our script + expect(body.attributes.cause.join(',')).contain('"hello with error'); + }); }); describe('update', () => { @@ -248,6 +268,32 @@ export default function ({ getService }) { catTemplateResponse.find(({ name: templateName }) => templateName === name).version ).to.equal(updatedVersion.toString()); }); + + it('should parse the ES error and return the cause', async () => { + const templateName = `template-${getRandomString()}`; + const payload = getTemplatePayload(templateName, [getRandomString()]); + const runtime = { + myRuntimeField: { + type: 'keyword', + script: { + source: 'emit("hello")', + }, + }, + }; + + // Add runtime field + payload.template.mappings = { ...payload.template.mappings, runtime }; + + await createTemplate(payload).expect(200); + + // Update template with an error in the runtime field script + payload.template.mappings.runtime.myRuntimeField.script = 'emit("hello with error'; + const { body } = await updateTemplate(payload, templateName).expect(400); + + expect(body.attributes).an('object'); + // one of the item of the cause array should point to our script + expect(body.attributes.cause.join(',')).contain('"hello with error'); + }); }); describe('delete', () => {