Skip to content

Commit c93c07b

Browse files
add api integration tests
1 parent 0ab60c1 commit c93c07b

File tree

5 files changed

+188
-0
lines changed

5 files changed

+188
-0
lines changed

x-pack/test/api_integration/apis/management/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export default function({ loadTestFile }) {
1212
loadTestFile(require.resolve('./rollup'));
1313
loadTestFile(require.resolve('./index_management'));
1414
loadTestFile(require.resolve('./index_lifecycle_management'));
15+
loadTestFile(require.resolve('./ingest_pipelines'));
1516
});
1617
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { FtrProviderContext } from '../../../ftr_provider_context';
7+
8+
export default function({ loadTestFile }: FtrProviderContext) {
9+
describe('Ingest Node Pipelines', () => {
10+
loadTestFile(require.resolve('./ingest_pipelines'));
11+
});
12+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import expect from '@kbn/expect';
8+
import { registerEsHelpers } from './lib';
9+
10+
import { FtrProviderContext } from '../../../ftr_provider_context';
11+
12+
const API_BASE_PATH = '/api/ingest_pipelines';
13+
14+
export default function({ getService }: FtrProviderContext) {
15+
const supertest = getService('supertest');
16+
17+
const { createPipeline, deletePipeline } = registerEsHelpers(getService);
18+
19+
describe('Pipelines', function() {
20+
describe('Create', () => {
21+
const PIPELINE_ID = 'test_create_pipeline';
22+
after(() => deletePipeline(PIPELINE_ID));
23+
24+
it('should create a pipeline', async () => {
25+
const { body } = await supertest
26+
.put(API_BASE_PATH)
27+
.set('kbn-xsrf', 'xxx')
28+
.send({
29+
name: PIPELINE_ID,
30+
description: 'test pipeline description',
31+
processors: [
32+
{
33+
script: {
34+
source: 'ctx._type = null',
35+
},
36+
},
37+
],
38+
version: 1,
39+
})
40+
.expect(200);
41+
42+
expect(body).to.eql({
43+
acknowledged: true,
44+
});
45+
});
46+
47+
it('should not allow creation of an existing pipeline', async () => {
48+
const { body } = await supertest
49+
.put(API_BASE_PATH)
50+
.set('kbn-xsrf', 'xxx')
51+
.send({
52+
name: PIPELINE_ID,
53+
description: 'test pipeline description',
54+
processors: [
55+
{
56+
script: {
57+
source: 'ctx._type = null',
58+
},
59+
},
60+
],
61+
version: 1,
62+
})
63+
.expect(409);
64+
65+
expect(body).to.eql({
66+
statusCode: 409,
67+
error: 'Conflict',
68+
message: `There is already a pipeline with name '${PIPELINE_ID}'.`,
69+
});
70+
});
71+
});
72+
73+
describe('Update', () => {
74+
const PIPELINE_ID = 'test_update_pipeline';
75+
const PIPELINE = {
76+
description: 'test pipeline description',
77+
processors: [
78+
{
79+
script: {
80+
source: 'ctx._type = null',
81+
},
82+
},
83+
],
84+
version: 1,
85+
};
86+
87+
before(() => createPipeline({ body: PIPELINE, id: PIPELINE_ID }));
88+
after(() => deletePipeline(PIPELINE_ID));
89+
90+
it('should allow an existing pipeline to be updated', async () => {
91+
const uri = `${API_BASE_PATH}/${PIPELINE_ID}`;
92+
93+
const { body } = await supertest
94+
.put(uri)
95+
.set('kbn-xsrf', 'xxx')
96+
.send({
97+
...PIPELINE,
98+
description: 'updated test pipeline description',
99+
})
100+
.expect(200);
101+
102+
expect(body).to.eql({
103+
acknowledged: true,
104+
});
105+
});
106+
107+
it('should not allow a non-existing pipeline to be updated', async () => {
108+
const uri = `${API_BASE_PATH}/pipeline_does_not_exist`;
109+
110+
const { body } = await supertest
111+
.put(uri)
112+
.set('kbn-xsrf', 'xxx')
113+
.send({
114+
...PIPELINE,
115+
description: 'updated test pipeline description',
116+
})
117+
.expect(404);
118+
119+
expect(body).to.eql({
120+
statusCode: 404,
121+
error: 'Not Found',
122+
message: 'Not Found',
123+
});
124+
});
125+
});
126+
});
127+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { FtrProviderContext } from '../../../../ftr_provider_context';
7+
8+
interface Pipeline {
9+
id: string;
10+
body: {
11+
description: string;
12+
processors: any[];
13+
version?: number;
14+
};
15+
}
16+
17+
/**
18+
* Helpers to create and delete indices on the Elasticsearch instance
19+
* during our tests.
20+
* @param {ElasticsearchClient} es The Elasticsearch client instance
21+
*/
22+
export const registerEsHelpers = (getService: FtrProviderContext['getService']) => {
23+
const es = getService('legacyEs');
24+
25+
let pipelinesCreated: Pipeline[] = [];
26+
27+
const createPipeline = (pipeline: Pipeline) => {
28+
pipelinesCreated.push(pipeline);
29+
return es.ingest.putPipeline(pipeline).then(() => pipeline);
30+
};
31+
32+
const deletePipeline = (pipelineId: string) => {
33+
pipelinesCreated = pipelinesCreated.filter(({ id }) => id !== pipelineId);
34+
return es.ingest.deletePipeline({ id: pipelineId });
35+
};
36+
37+
return {
38+
createPipeline,
39+
deletePipeline,
40+
};
41+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { registerEsHelpers } from './elasticsearch';

0 commit comments

Comments
 (0)