Merge pull request #6478 from Bargs/ingest/pipelineApiTests

Adding some API tests for pipelines in the ingest API
This commit is contained in:
Matt Bargar 2016-03-08 17:57:20 -05:00
commit 9620319a90
4 changed files with 40 additions and 2 deletions

View file

@ -4,5 +4,5 @@ const pipelineSchema = require('./pipeline_schema');
module.exports = Joi.object({
index_pattern: indexPatternSchema.required(),
pipeline: pipelineSchema.required()
pipeline: pipelineSchema
});

View file

@ -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);
@ -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);});

View file

@ -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);
});
});
});

View file

@ -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())