Skip to content

Commit

Permalink
[Index Management] Add settings route api tests (#172042)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba authored Nov 29, 2023
1 parent b794378 commit a766fe6
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { IndexSettings } from '@kbn/index-management-plugin/common';

import { API_BASE_PATH } from '../constants';
import { FtrProviderContext } from '../../../../ftr_provider_context';

export function settingsApi(getService: FtrProviderContext['getService']) {
const supertest = getService('supertest');

const getIndexSettings = (index: string) =>
supertest
.get(`${API_BASE_PATH}/settings/${index}`)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx');

const updateIndexSettings = (index: string, settings: IndexSettings) =>
supertest
.put(`${API_BASE_PATH}/settings/${index}`)
.set('kbn-xsrf', 'xxx')
.set('x-elastic-internal-origin', 'xxx')
.send(settings);

return {
getIndexSettings,
updateIndexSettings,
};
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import expect from '@kbn/expect';

import { indicesHelpers } from './lib/indices.helpers';
import { registerHelpers } from './settings.helpers';

export default function ({ getService }) {
const supertest = getService('supertest');
import { settingsApi } from './lib/settings.api';
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const { createIndex, deleteAllIndices } = indicesHelpers(getService);

const { getIndexSettings, updateIndexSettings } = registerHelpers({ supertest });
const { getIndexSettings, updateIndexSettings } = settingsApi(getService);

describe('settings', () => {
after(async () => await deleteAllIndices());
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/api_integration/services/index_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FtrProviderContext } from '../ftr_provider_context';
import { indicesApi } from '../apis/management/index_management/lib/indices.api';
import { mappingsApi } from '../apis/management/index_management/lib/mappings.api';
import { indicesHelpers } from '../apis/management/index_management/lib/indices.helpers';
import { settingsApi } from '../apis/management/index_management/lib/settings.api';
import { clusterNodesApi } from '../apis/management/index_management/lib/cluster_nodes.api';
import { datastreamsHelpers } from '../apis/management/index_management/lib/datastreams.helpers';

Expand All @@ -27,5 +28,8 @@ export function IndexManagementProvider({ getService }: FtrProviderContext) {
mappings: {
api: mappingsApi(getService),
},
settings: {
api: settingsApi(getService),
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./cluster_nodes'));
loadTestFile(require.resolve('./datastreams'));
loadTestFile(require.resolve('./mappings'));
loadTestFile(require.resolve('./settings'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';

import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const indexManagementService = getService('indexManagement');

describe('settings', () => {
let getIndexSettings: typeof indexManagementService['settings']['api']['getIndexSettings'];
let updateIndexSettings: typeof indexManagementService['settings']['api']['updateIndexSettings'];
let createIndex: typeof indexManagementService['indices']['helpers']['createIndex'];
let deleteAllIndices: typeof indexManagementService['indices']['helpers']['deleteAllIndices'];

before(async () => {
({
settings: {
api: { getIndexSettings, updateIndexSettings },
},
indices: {
helpers: { createIndex, deleteAllIndices },
},
} = indexManagementService);
});

after(async () => await deleteAllIndices());

it('should fetch an index settings', async () => {
const index = await createIndex();

const { body } = await getIndexSettings(index).expect(200);

// Verify we fetch the corret index settings
expect(body.settings.index.provided_name).to.be(index);

const expectedSettings = [
'max_inner_result_window',
'unassigned',
'max_terms_count',
'lifecycle',
'routing_partition_size',
'max_docvalue_fields_search',
'merge',
'max_refresh_listeners',
'max_regex_length',
'load_fixed_bitset_filters_eagerly',
'number_of_routing_shards',
'write',
'verified_before_close',
'mapping',
'source_only',
'soft_deletes',
'max_script_fields',
'query',
'format',
'frozen',
'sort',
'priority',
'codec',
'max_rescore_window',
'analyze',
'gc_deletes',
'max_ngram_diff',
'translog',
'auto_expand_replicas',
'requests',
'data_path',
'highlight',
'routing',
'search',
'fielddata',
'default_pipeline',
'max_slices_per_scroll',
'shard',
'xpack',
'percolator',
'allocation',
'refresh_interval',
'indexing',
'compound_format',
'blocks',
'max_result_window',
'store',
'queries',
'warmer',
'max_shingle_diff',
'query_string',
];

// Make sure none of the settings have been removed from ES API
expectedSettings.forEach((setting) => {
try {
expect(body.defaults.index.hasOwnProperty(setting)).to.be(true);
} catch {
throw new Error(`Expected setting "${setting}" not found.`);
}
});
});

it('should update an index settings', async () => {
const index = await createIndex();

const { body: body1 } = await getIndexSettings(index);
expect(body1.settings.index.number_of_replicas).to.be('1');

const settings = {
index: {
number_of_replicas: 2,
},
};
await updateIndexSettings(index, settings);

const { body: body2 } = await getIndexSettings(index);
expect(body2.settings.index.number_of_replicas).to.be('2');
});
});
}

0 comments on commit a766fe6

Please sign in to comment.