forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Index management] Api integration tests (elastic#36343)
- Loading branch information
Showing
16 changed files
with
666 additions
and
36 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
x-pack/plugins/index_management/server/routes/api/indices/register_settings_route.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
x-pack/test/api_integration/apis/management/index_management/constants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export const API_BASE_PATH = '/api/index_management'; |
14 changes: 14 additions & 0 deletions
14
x-pack/test/api_integration/apis/management/index_management/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export default function ({ loadTestFile }) { | ||
describe('index management', () => { | ||
loadTestFile(require.resolve('./indices')); | ||
loadTestFile(require.resolve('./mapping')); | ||
loadTestFile(require.resolve('./settings')); | ||
loadTestFile(require.resolve('./stats')); | ||
}); | ||
} |
57 changes: 57 additions & 0 deletions
57
x-pack/test/api_integration/apis/management/index_management/indices.helpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { API_BASE_PATH } from './constants'; | ||
|
||
export const registerHelpers = ({ supertest }) => { | ||
const executeActionOnIndices = (index, urlParam, args) => { | ||
const indices = Array.isArray(index) ? index : [index]; | ||
|
||
return supertest.post(`${API_BASE_PATH}/indices/${urlParam}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ indices, ...args }); | ||
}; | ||
|
||
const closeIndex = (index) => executeActionOnIndices(index, 'close'); | ||
|
||
const openIndex = (index) => executeActionOnIndices(index, 'open'); | ||
|
||
const deleteIndex = (index) => executeActionOnIndices(index, 'delete'); | ||
|
||
const flushIndex = (index) => executeActionOnIndices(index, 'flush'); | ||
|
||
const refreshIndex = (index) => executeActionOnIndices(index, 'refresh'); | ||
|
||
const forceMerge = (index, args) => executeActionOnIndices(index, 'forcemerge', args); | ||
|
||
const freeze = (index) => executeActionOnIndices(index, 'freeze'); | ||
|
||
const unfreeze = (index) => executeActionOnIndices(index, 'unfreeze'); | ||
|
||
const clearCache = (index) => executeActionOnIndices(index, 'clear_cache'); | ||
|
||
const list = () => supertest.get(`${API_BASE_PATH}/indices`); | ||
|
||
const reload = (indexNames) => ( | ||
supertest.post(`${API_BASE_PATH}/indices/reload`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ indexNames }) | ||
); | ||
|
||
return { | ||
closeIndex, | ||
openIndex, | ||
deleteIndex, | ||
flushIndex, | ||
refreshIndex, | ||
forceMerge, | ||
freeze, | ||
unfreeze, | ||
list, | ||
reload, | ||
clearCache, | ||
}; | ||
}; |
226 changes: 226 additions & 0 deletions
226
x-pack/test/api_integration/apis/management/index_management/indices.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
|
||
import { initElasticsearchHelpers } from './lib'; | ||
import { registerHelpers } from './indices.helpers'; | ||
|
||
export default function ({ getService }) { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
const { | ||
createIndex, | ||
catIndex, | ||
indexStats, | ||
cleanUp: cleanUpEsResources | ||
} = initElasticsearchHelpers(es); | ||
|
||
const { | ||
closeIndex, | ||
openIndex, | ||
deleteIndex, | ||
flushIndex, | ||
refreshIndex, | ||
forceMerge, | ||
freeze, | ||
unfreeze, | ||
list, | ||
reload, | ||
clearCache, | ||
} = registerHelpers({ supertest }); | ||
|
||
describe('indices', () => { | ||
after(() => Promise.all([cleanUpEsResources()])); | ||
|
||
describe('clear cache', () => { | ||
it('should clear the cache on all indices', async () => { | ||
await clearCache('*').expect(200); | ||
}); | ||
|
||
it('should clear the cache on a single index', async () => { | ||
const index = await createIndex(); | ||
await clearCache(index).expect(200); | ||
}); | ||
}); | ||
|
||
describe('close', () => { | ||
it('should close an index', async () => { | ||
const index = await createIndex(); | ||
|
||
// Make sure the index is open | ||
const [cat1] = await catIndex(index); | ||
expect(cat1.status).to.be('open'); | ||
|
||
await closeIndex(index).expect(200); | ||
|
||
// Make sure the index has been closed | ||
const [cat2] = await catIndex(index); | ||
expect(cat2.status).to.be('close'); | ||
}); | ||
}); | ||
|
||
describe('open', () => { | ||
it('should open an index', async () => { | ||
const index = await createIndex(); | ||
|
||
await closeIndex(index); | ||
|
||
// Make sure the index is closed | ||
const [cat1] = await catIndex(index); | ||
expect(cat1.status).to.be('close'); | ||
|
||
await openIndex(index).expect(200); | ||
|
||
// Make sure the index is opened | ||
const [cat2] = await catIndex(index); | ||
expect(cat2.status).to.be('open'); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should delete an index', async () => { | ||
const index = await createIndex(); | ||
|
||
const indices1 = await catIndex(undefined, 'i'); | ||
expect(indices1.map(index => index.i)).to.contain(index); | ||
|
||
await deleteIndex([index]).expect(200); | ||
|
||
const indices2 = await catIndex(undefined, 'i'); | ||
expect(indices2.map(index => index.i)).not.to.contain(index); | ||
}); | ||
|
||
it('should require index or indices to be provided', async () => { | ||
const { body } = await deleteIndex().expect(400); | ||
expect(body.message).to.contain('index / indices is missing'); | ||
}); | ||
}); | ||
|
||
describe('flush', () => { | ||
it('should flush an index', async () => { | ||
const index = await createIndex(); | ||
|
||
const { indices: indices1 } = await indexStats(index, 'flush'); | ||
expect(indices1[index].total.flush.total).to.be(0); | ||
|
||
await flushIndex(index).expect(200); | ||
|
||
const { indices: indices2 } = await indexStats(index, 'flush'); | ||
expect(indices2[index].total.flush.total).to.be(1); | ||
}); | ||
}); | ||
|
||
describe('refresh', () => { | ||
it('should refresh an index', async () => { | ||
const index = await createIndex(); | ||
|
||
const { indices: indices1 } = await indexStats(index, 'refresh'); | ||
const previousRefreshes = indices1[index].total.refresh.total; | ||
|
||
await refreshIndex(index).expect(200); | ||
|
||
const { indices: indices2 } = await indexStats(index, 'refresh'); | ||
expect(indices2[index].total.refresh.total).to.be(previousRefreshes + 1); | ||
}); | ||
}); | ||
|
||
describe('forcemerge', () => { | ||
it('should force merge an index', async () => { | ||
const index = await createIndex(); | ||
await forceMerge(index).expect(200); | ||
}); | ||
|
||
it('should allow to define the number of segments', async () => { | ||
const index = await createIndex(); | ||
await forceMerge(index, { max_num_segments: 1 }).expect(200); | ||
}); | ||
}); | ||
|
||
describe('freeze', () => { | ||
it('should freeze an index', async () => { | ||
const index = await createIndex(); | ||
// "sth" correspond to search throttling. Frozen indices are normal indices | ||
// with search throttling turned on. | ||
const [cat1] = await catIndex(index, 'sth'); | ||
expect(cat1.sth).to.be('false'); | ||
|
||
await freeze(index).expect(200); | ||
|
||
const [cat2] = await catIndex(index, 'sth'); | ||
expect(cat2.sth).to.be('true'); | ||
}); | ||
}); | ||
|
||
describe('unfreeze', () => { | ||
it('should unfreeze an index', async () => { | ||
const index = await createIndex(); | ||
|
||
await freeze(index).expect(200); | ||
const [cat1] = await catIndex(index, 'sth'); | ||
expect(cat1.sth).to.be('true'); | ||
|
||
await unfreeze(index).expect(200); | ||
const [cat2] = await catIndex(index, 'sth'); | ||
expect(cat2.sth).to.be('false'); | ||
}); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should list all the indices with the expected properties and data enrichers', async () => { | ||
const { body } = await list().expect(200); | ||
const expectedKeys = [ | ||
'health', | ||
'status', | ||
'name', | ||
'uuid', | ||
'primary', | ||
'replica', | ||
'documents', | ||
'size', | ||
'isFrozen', | ||
'aliases', | ||
'ilm', // data enricher | ||
'isRollupIndex', // data enricher | ||
'isFollowerIndex' // data enricher | ||
]; | ||
expect(Object.keys(body[0])).to.eql(expectedKeys); | ||
}); | ||
}); | ||
|
||
describe('reload', () => { | ||
it('should list all the indices with the expected properties and data enrichers', async () => { | ||
const { body } = await reload().expect(200); | ||
const expectedKeys = [ | ||
'health', | ||
'status', | ||
'name', | ||
'uuid', | ||
'primary', | ||
'replica', | ||
'documents', | ||
'size', | ||
'isFrozen', | ||
'aliases', | ||
'ilm', // data enricher | ||
'isRollupIndex', // data enricher | ||
'isFollowerIndex' // data enricher | ||
]; | ||
expect(Object.keys(body[0])).to.eql(expectedKeys); | ||
expect(body.length > 1).to.be(true); // to contrast it with the next test | ||
}); | ||
|
||
it('should allow reloading only certain indices', async () => { | ||
const index = await createIndex(); | ||
const { body } = await reload([index]); | ||
|
||
expect(body.length === 1).to.be(true); | ||
expect(body[0].name).to.be(index); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.