From 9816c28637030b9b2be2f17293c3176f1d8b3e70 Mon Sep 17 00:00:00 2001 From: Sergi Massaneda Date: Sun, 10 Nov 2024 19:28:39 +0100 Subject: [PATCH] fix tests --- .../src/create_or_update_index.test.ts | 2 +- .../src/create_or_update_index.ts | 18 +++++++----------- .../src/resource_installer_utils.test.ts | 12 ++++++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/kbn-index-adapter/src/create_or_update_index.test.ts b/packages/kbn-index-adapter/src/create_or_update_index.test.ts index 5811807719ac8..d219fd283c13b 100644 --- a/packages/kbn-index-adapter/src/create_or_update_index.test.ts +++ b/packages/kbn-index-adapter/src/create_or_update_index.test.ts @@ -40,7 +40,7 @@ describe('updateIndices', () => { }); expect(esClient.indices.get).toHaveBeenCalledWith({ - index: `${name}*`, + index: name, expand_wildcards: 'all', }); diff --git a/packages/kbn-index-adapter/src/create_or_update_index.ts b/packages/kbn-index-adapter/src/create_or_update_index.ts index 420ba3b27b0ef..ff825c61305b7 100644 --- a/packages/kbn-index-adapter/src/create_or_update_index.ts +++ b/packages/kbn-index-adapter/src/create_or_update_index.ts @@ -146,14 +146,7 @@ export async function createOrUpdateIndex({ }); } else { try { - await retryTransientEsErrors( - () => - esClient.indices.create({ - index: name, - mappings: { _meta: { name: 'migration name #1' } }, - }), - { logger } - ); + await retryTransientEsErrors(() => esClient.indices.create({ index: name }), { logger }); } catch (error) { if (error?.meta?.body?.error?.type !== 'resource_already_exists_exception') { logger.error(`Error creating index ${name} - ${error.message}`); @@ -175,9 +168,12 @@ export async function createIndex({ logger, esClient, name }: CreateIndexParams) // check if index exists let indexExists = false; try { - indexExists = await retryTransientEsErrors(() => esClient.indices.exists({ index: name }), { - logger, - }); + indexExists = await retryTransientEsErrors( + () => esClient.indices.exists({ index: name, expand_wildcards: 'all' }), + { + logger, + } + ); } catch (error) { if (error?.statusCode !== 404) { logger.error(`Error fetching index for ${name} - ${error.message}`); diff --git a/packages/kbn-index-adapter/src/resource_installer_utils.test.ts b/packages/kbn-index-adapter/src/resource_installer_utils.test.ts index 93d421bb5605c..31d4a3abcbb0d 100644 --- a/packages/kbn-index-adapter/src/resource_installer_utils.test.ts +++ b/packages/kbn-index-adapter/src/resource_installer_utils.test.ts @@ -24,7 +24,6 @@ describe('getIndexTemplate', () => { expect(indexTemplate).toEqual({ name: defaultParams.name, body: { - data_stream: { hidden: true }, index_patterns: defaultParams.indexPatterns, composed_of: defaultParams.componentTemplateRefs, template: { @@ -57,8 +56,17 @@ describe('getIndexTemplate', () => { }); }); + it('should create data stream index template with given parameters and defaults', () => { + const indexTemplate = getIndexTemplate({ ...defaultParams, isDataStream: true }); + expect(indexTemplate.body).toEqual( + expect.objectContaining({ + data_stream: { hidden: true }, + }) + ); + }); + it('should create not hidden index template', () => { - const { body } = getIndexTemplate({ ...defaultParams, hidden: false }); + const { body } = getIndexTemplate({ ...defaultParams, isDataStream: true, hidden: false }); expect(body?.data_stream?.hidden).toEqual(false); expect(body?.template?.settings?.hidden).toEqual(false); });