Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed Nov 10, 2024
1 parent 47c6321 commit 9816c28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('updateIndices', () => {
});

expect(esClient.indices.get).toHaveBeenCalledWith({
index: `${name}*`,
index: name,
expand_wildcards: 'all',
});

Expand Down
18 changes: 7 additions & 11 deletions packages/kbn-index-adapter/src/create_or_update_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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}`);
Expand Down
12 changes: 10 additions & 2 deletions packages/kbn-index-adapter/src/resource_installer_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 9816c28

Please sign in to comment.