Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API integration test for deleting data streams. #70020

Merged
merged 4 commits into from
Jun 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,79 +19,131 @@ export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const es = getService('legacyEs');

const createDataStream = (name: string) => {
const createDataStream = async (name: string) => {
// A data stream requires an index template before it can be created.
return es.dataManagement
.saveComposableIndexTemplate({
name,
body: {
// We need to match the names of backing indices with this template
index_patterns: [name + '*'],
template: {
mappings: {
properties: {
'@timestamp': {
type: 'date',
},
await es.dataManagement.saveComposableIndexTemplate({
name,
body: {
// We need to match the names of backing indices with this template.
index_patterns: [name + '*'],
template: {
mappings: {
properties: {
'@timestamp': {
type: 'date',
},
},
},
data_stream: {
timestamp_field: '@timestamp',
},
},
})
.then(() =>
es.dataManagement.createDataStream({
name,
})
);
data_stream: {
timestamp_field: '@timestamp',
},
},
});

await es.dataManagement.createDataStream({ name });
};

const deleteDataStream = (name: string) => {
return es.dataManagement
.deleteDataStream({
name,
})
.then(() =>
es.dataManagement.deleteComposableIndexTemplate({
name,
})
);
const deleteComposableIndexTemplate = async (name: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor nit; but not convinced we gain much with this function declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was required for cleanup on this line: https://github.com/elastic/kibana/pull/70020/files#diff-1f60ccfa4a646384a55910a832d7cfd1R123. Because the deletion API only deletes the data streams, we are still left needing to clean up their related index templates after the tests run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave a comment in the code to make that more obvious.

await es.dataManagement.deleteComposableIndexTemplate({ name });
};

// Unskip once ES snapshot has been promoted that updates the data stream response
describe.skip('Data streams', function () {
const testDataStreamName = 'test-data-stream';
const deleteDataStream = async (name: string) => {
await es.dataManagement.deleteDataStream({ name });
await deleteComposableIndexTemplate(name);
};

describe('Data streams', function () {
describe('Get', () => {
const testDataStreamName = 'test-data-stream';

before(async () => await createDataStream(testDataStreamName));
after(async () => await deleteDataStream(testDataStreamName));

describe('all data streams', () => {
it('returns an array of data streams', async () => {
const { body: dataStreams } = await supertest
.get(`${API_BASE_PATH}/data_streams`)
.set('kbn-xsrf', 'xxx')
.expect(200);
it('returns an array of all data streams', async () => {
const { body: dataStreams } = await supertest
.get(`${API_BASE_PATH}/data_streams`)
.set('kbn-xsrf', 'xxx')
.expect(200);

// ES determines these values so we'll just echo them back.
const { name: indexName, uuid } = dataStreams[0].indices[0];
expect(dataStreams).to.eql([
{
name: testDataStreamName,
timeStampField: { name: '@timestamp', mapping: { type: 'date' } },
indices: [
{
name: indexName,
uuid,
},
],
generation: 1,
},
]);
});

it('returns a single data stream by ID', async () => {
const { body: dataStream } = await supertest
.get(`${API_BASE_PATH}/data_streams/${testDataStreamName}`)
.set('kbn-xsrf', 'xxx')
.expect(200);

// ES determines these values so we'll just echo them back.
const { name: indexName, uuid } = dataStreams[0].indices[0];
expect(dataStreams).to.eql([
// ES determines these values so we'll just echo them back.
const { name: indexName, uuid } = dataStream.indices[0];
expect(dataStream).to.eql({
name: testDataStreamName,
timeStampField: { name: '@timestamp', mapping: { type: 'date' } },
indices: [
{
name: testDataStreamName,
timeStampField: { name: '@timestamp', mapping: { type: 'date' } },
indices: [
{
name: indexName,
uuid,
},
],
generation: 1,
name: indexName,
uuid,
},
]);
],
generation: 1,
});
});
});

describe('Delete', () => {
const testDataStreamName1 = 'test-data-stream1';
const testDataStreamName2 = 'test-data-stream2';

before(async () => {
await Promise.all([
createDataStream(testDataStreamName1),
createDataStream(testDataStreamName2),
]);
});

after(async () => {
// The Delete API only deletes the data streams, so we still need to manually delete their
// related index patterns to clean up.
await Promise.all([
deleteComposableIndexTemplate(testDataStreamName1),
deleteComposableIndexTemplate(testDataStreamName2),
]);
});

it('deletes multiple data streams', async () => {
await supertest
.post(`${API_BASE_PATH}/delete_data_streams`)
.set('kbn-xsrf', 'xxx')
.send({
dataStreams: [testDataStreamName1, testDataStreamName2],
})
.expect(200);

await supertest
.get(`${API_BASE_PATH}/data_streams/${testDataStreamName1}`)
.set('kbn-xsrf', 'xxx')
.expect(404);

await supertest
.get(`${API_BASE_PATH}/data_streams/${testDataStreamName2}`)
.set('kbn-xsrf', 'xxx')
.expect(404);
});
});
});
}