mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[add data] added error-flow tests to the _simulate suite
This commit is contained in:
parent
c63a5a2c76
commit
ea71928f72
4 changed files with 104 additions and 24 deletions
|
@ -1,9 +1,10 @@
|
|||
const _ = require('lodash');
|
||||
|
||||
function buildError(error) {
|
||||
const errorMessage = _.get(error, 'body.error.root_cause[0].reason');
|
||||
if (!errorMessage) throw error;
|
||||
const processorId = _.get(error, 'body.error.root_cause[0].header.processor_tag');
|
||||
if (!processorId) throw error;
|
||||
|
||||
const errorMessage = _.get(error, 'body.error.root_cause[0].reason');
|
||||
return {
|
||||
compile: true,
|
||||
message: errorMessage
|
||||
|
|
|
@ -19,7 +19,6 @@ export function registerSimulate(server) {
|
|||
const boundCallWithRequest = _.partial(server.plugins.elasticsearch.callWithRequest, request);
|
||||
const simulateApiDocument = request.payload;
|
||||
const body = ingestSimulateApiKibanaToEsConverter(simulateApiDocument);
|
||||
|
||||
const handleError = _.partial(processESIngestSimulateError, simulateApiDocument.dirty_processor_id);
|
||||
|
||||
return boundCallWithRequest('transport.request', {
|
||||
|
|
|
@ -52,6 +52,107 @@ define(function (require) {
|
|||
.expect(200);
|
||||
});
|
||||
|
||||
bdd.describe('compilation errors', function simulatePipeline() {
|
||||
const pipeline = {
|
||||
input: { foo: '[message]' },
|
||||
processors: [
|
||||
{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'set',
|
||||
target_field: 'foo',
|
||||
value: 'bar'
|
||||
},
|
||||
{
|
||||
processor_id: 'processor2',
|
||||
type_id: 'gsub',
|
||||
source_field: 'foo',
|
||||
pattern: '[',
|
||||
replacement: '<'
|
||||
},
|
||||
{
|
||||
processor_id: 'processor3',
|
||||
type_id: 'set',
|
||||
target_field: 'bar',
|
||||
value: 'baz'
|
||||
}
|
||||
],
|
||||
dirty_processor_id: 'processor2'
|
||||
};
|
||||
|
||||
bdd.it('should return a 200 for a compile error caused by a processor', function () {
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send(pipeline)
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.body[0].processor_id).to.be('processor2');
|
||||
expect(response.body[0].error.compile).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should only return a result for the processor that threw the error', function () {
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send(pipeline)
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.body[0].processor_id).to.be('processor2');
|
||||
expect(response.body[0].error.compile).to.be(true);
|
||||
expect(response.body.length).to.be(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.describe('data errors', function simulatePipeline() {
|
||||
const pipeline = {
|
||||
input: { foo: '[message]' },
|
||||
processors: [
|
||||
{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'set',
|
||||
target_field: 'foo',
|
||||
value: 'bar'
|
||||
},
|
||||
{
|
||||
processor_id: 'processor2',
|
||||
type_id: 'gsub',
|
||||
source_field: '', //invalid source field
|
||||
pattern: '\\[',
|
||||
replacement: '<'
|
||||
},
|
||||
{
|
||||
processor_id: 'processor3',
|
||||
type_id: 'set',
|
||||
target_field: 'bar',
|
||||
value: 'baz'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
bdd.it('should return 200 with non-compile error object for a processor with an invalid source_field', () => {
|
||||
return Promise.all([
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send(pipeline)
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.body[0].error).to.be(undefined);
|
||||
expect(response.body[1].error.compile).to.be(false);
|
||||
expect(response.body[1].processor_id).to.be('processor2');
|
||||
})
|
||||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return results up to and including the erroring processor', () => {
|
||||
return Promise.all([
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send(pipeline)
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.body.length).to.be(2);
|
||||
})
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
|
@ -35,27 +35,6 @@ define(function (require) {
|
|||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return a compile error object for a processor with an invalid regex', () => {
|
||||
return Promise.all([
|
||||
// non-escaped square bracket is an invalid regex
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
input: { foo: 'bar' },
|
||||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'gsub',
|
||||
source_field: 'foo',
|
||||
pattern: '[',
|
||||
replacement: 'baz'
|
||||
}]
|
||||
})
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.body[0].error.compile).to.be(true);
|
||||
})
|
||||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return 200 for a valid simulate request', () => {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send(testPipeline)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue