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

Adding some API tests for pipelines in the ingest API #6478

Merged
merged 2 commits into from
Mar 8, 2016
Merged
Show file tree
Hide file tree
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 @@ -4,5 +4,5 @@ const pipelineSchema = require('./pipeline_schema');

module.exports = Joi.object({
index_pattern: indexPatternSchema.required(),
pipeline: pipelineSchema.required()
pipeline: pipelineSchema
});
7 changes: 6 additions & 1 deletion src/plugins/kibana/server/routes/api/ingest/register_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = function registerPost(server) {
const indexPattern = keysToCamelCaseShallow(requestDocument.index_pattern);
const indexPatternId = indexPattern.id;
const ingestConfigName = patternToIngest(indexPatternId);
const shouldCreatePipeline = !_.isEmpty(requestDocument.pipeline);
delete indexPattern.id;

const mappings = createMappingsFromPatternFields(indexPattern.fields);
Expand Down Expand Up @@ -132,7 +133,11 @@ module.exports = function registerPost(server) {
return boundCallWithRequest('indices.putTemplate', templateParams)
.catch((templateError) => {return patternRollback(templateError, indexPatternId, boundCallWithRequest);});
})
.then(() => {
.then((templateResponse) => {
if (!shouldCreatePipeline) {
return templateResponse;
}

return boundCallWithRequest('transport.request', pipelineParams)
.catch((pipelineError) => {return templateRollback(pipelineError, ingestConfigName, boundCallWithRequest);})
.catch((templateRollbackError) => {return patternRollback(templateRollbackError, indexPatternId, boundCallWithRequest);});
Expand Down
9 changes: 9 additions & 0 deletions test/unit/api/ingest/_del.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ define(function (require) {
.catch(function (error) {
expect(error.status).to.be(404);
});
})
.then(function () {
return scenarioManager.client.transport.request({
path: '_ingest/pipeline/kibana-logstash-*',
method: 'GET'
})
.catch(function (error) {
expect(error.status).to.be(404);
});
});
});

Expand Down
24 changes: 24 additions & 0 deletions test/unit/api/ingest/_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ define(function (require) {
});
});

bdd.it('should create a pipeline if one is included in the request', function () {
return request.post('/kibana/ingest')
.send(createTestData())
.expect(204)
.then(function () {
return scenarioManager.client.transport.request({
path: '_ingest/pipeline/kibana-logstash-*',
method: 'GET'
})
.then(function (body) {
expect(body.pipelines[0].id).to.be('kibana-logstash-*');
});
});
});

bdd.it('pipeline should be optional', function optionalPipeline() {
const payload = createTestData();
delete payload.pipeline;

return request.post('/kibana/ingest')
.send(payload)
.expect(204);
});

bdd.it('should return 409 conflict when a pattern with the given ID already exists', function patternConflict() {
return request.post('/kibana/ingest')
.send(createTestData())
Expand Down