mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
use snake case throughout the ingest simulate API
This commit is contained in:
parent
8f0ffd2402
commit
6b3f844264
4 changed files with 66 additions and 56 deletions
|
@ -5,25 +5,21 @@ import processESIngestSimulateResponse from '../process_es_ingest_simulate_respo
|
|||
describe('processESIngestSimulateResponse', function () {
|
||||
|
||||
it('returns a result for each processor in the pipeline', function () {
|
||||
const pipeline = {
|
||||
processors: [ { processorId: 'processor1' }, { processorId: 'processor2' } ]
|
||||
};
|
||||
const processors = [ { processorId: 'processor1' }, { processorId: 'processor2' } ];
|
||||
const response = {
|
||||
docs: [ { processor_results: [] } ]
|
||||
};
|
||||
|
||||
const results = processESIngestSimulateResponse(pipeline, response);
|
||||
const results = processESIngestSimulateResponse(processors, response);
|
||||
expect(results.length).to.be(2);
|
||||
});
|
||||
|
||||
it('each processor that does not receive a result will contain default info', function () {
|
||||
const pipeline = {
|
||||
processors: [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
]
|
||||
};
|
||||
const processors = [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
];
|
||||
const response = {
|
||||
docs: [ { processor_results: [] } ]
|
||||
};
|
||||
|
@ -33,19 +29,17 @@ describe('processESIngestSimulateResponse', function () {
|
|||
{ processorId: 'processor2', output: 'bar', error: undefined },
|
||||
{ processorId: 'processor3', output: 'baz', error: undefined }
|
||||
];
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
const actual = processESIngestSimulateResponse(processors, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
||||
it('each processor that receives a result will contain response info', function () {
|
||||
const pipeline = {
|
||||
processors: [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
]
|
||||
};
|
||||
const processors = [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
];
|
||||
const response = {
|
||||
docs: [ { processor_results: [
|
||||
{ tag: 'processor2', doc: { _source: 'new_bar' }, error: undefined },
|
||||
|
@ -58,7 +52,7 @@ describe('processESIngestSimulateResponse', function () {
|
|||
{ processorId: 'processor2', output: 'new_bar', error: undefined },
|
||||
{ processorId: 'processor3', output: 'new_baz', error: undefined }
|
||||
];
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
const actual = processESIngestSimulateResponse(processors, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
@ -66,13 +60,11 @@ describe('processESIngestSimulateResponse', function () {
|
|||
describe('processors that return an error object', function () {
|
||||
|
||||
it('will be the root_cause reason if one exists', function () {
|
||||
const pipeline = {
|
||||
processors: [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
]
|
||||
};
|
||||
const processors = [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
];
|
||||
const response = {
|
||||
docs: [ { processor_results: [
|
||||
{ tag: 'processor2', doc: { _source: 'new_bar' }, error: undefined },
|
||||
|
@ -89,19 +81,17 @@ describe('processESIngestSimulateResponse', function () {
|
|||
{ processorId: 'processor2', output: 'new_bar', error: undefined },
|
||||
{ processorId: 'processor3', output: undefined, error: { isNested: false, message: 'something bad happened'} }
|
||||
];
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
const actual = processESIngestSimulateResponse(processors, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
||||
it('will be the root_cause type if reason does not exists', function () {
|
||||
const pipeline = {
|
||||
processors: [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
]
|
||||
};
|
||||
const processors = [
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
];
|
||||
const response = {
|
||||
docs: [ { processor_results: [
|
||||
{ tag: 'processor2', doc: { _source: 'new_bar' }, error: undefined },
|
||||
|
@ -118,20 +108,18 @@ describe('processESIngestSimulateResponse', function () {
|
|||
{ processorId: 'processor2', output: 'new_bar', error: undefined },
|
||||
{ processorId: 'processor3', output: undefined, error: { isNested: false, message: 'something bad happened'} }
|
||||
];
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
const actual = processESIngestSimulateResponse(processors, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
||||
it('any processor after errored processor will be set to a nested error state', function () {
|
||||
const pipeline = {
|
||||
processors: [
|
||||
{ processorId: 'processor0', outputObject: 'oof' },
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
]
|
||||
};
|
||||
const processors = [
|
||||
{ processorId: 'processor0', outputObject: 'oof' },
|
||||
{ processorId: 'processor1', outputObject: 'foo' },
|
||||
{ processorId: 'processor2', outputObject: 'bar' },
|
||||
{ processorId: 'processor3', outputObject: 'baz' }
|
||||
];
|
||||
const response = {
|
||||
docs: [
|
||||
{
|
||||
|
@ -153,7 +141,7 @@ describe('processESIngestSimulateResponse', function () {
|
|||
{ processorId: 'processor2', output: undefined, error: { isNested: true, message: 'Invalid Parent Processor' } },
|
||||
{ processorId: 'processor3', output: undefined, error: { isNested: true, message: 'Invalid Parent Processor' } }
|
||||
];
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
const actual = processESIngestSimulateResponse(processors, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
|
|
@ -6,11 +6,11 @@ function translateError(esError) {
|
|||
return _.get(rootCause, 'reason') || _.get(rootCause, 'type');
|
||||
}
|
||||
|
||||
export default function processESIngestSimulateResponse(simulateApiDocument, resp) {
|
||||
const results = simulateApiDocument.processors.map((processor) => {
|
||||
export default function processESIngestSimulateResponse(processors, resp) {
|
||||
const results = processors.map((processor) => {
|
||||
return {
|
||||
processorId: processor.processor_id,
|
||||
output: processor.output_object,
|
||||
processorId: processor.processorId,
|
||||
output: processor.outputObject,
|
||||
error: undefined
|
||||
};
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ import _ from 'lodash';
|
|||
import processESIngestSimulateResponse from '../../../lib/process_es_ingest_simulate_response';
|
||||
import simulateRequestSchema from '../../../lib/schemas/simulate_request_schema';
|
||||
import ingestSimulateApiKibanaToEsConverter from '../../../lib/converters/ingest_simulate_api_kibana_to_es_converter';
|
||||
import { keysToCamelCaseShallow, keysToSnakeCaseShallow } from '../../../lib/case_conversion';
|
||||
|
||||
module.exports = function registerSimulate(server) {
|
||||
server.route({
|
||||
|
@ -23,7 +24,8 @@ module.exports = function registerSimulate(server) {
|
|||
method: 'POST',
|
||||
body: body
|
||||
})
|
||||
.then(_.partial(processESIngestSimulateResponse, simulateApiDocument))
|
||||
.then(_.partial(processESIngestSimulateResponse, _.map(simulateApiDocument.processors, keysToCamelCaseShallow)))
|
||||
.then((processors) => _.map(processors, keysToSnakeCaseShallow))
|
||||
.then(reply);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,16 +5,16 @@ define(function (require) {
|
|||
|
||||
const testPipeline = {
|
||||
processors: [{
|
||||
processorId: 'processor1',
|
||||
typeId: 'set',
|
||||
targetField: 'foo',
|
||||
processor_id: 'processor1',
|
||||
type_id: 'set',
|
||||
target_field: 'foo',
|
||||
value: 'bar'
|
||||
}],
|
||||
input: {}
|
||||
};
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('simulate', function simulatePipeline() {
|
||||
bdd.describe('simulate - set processor', function simulatePipeline() {
|
||||
|
||||
bdd.it('should return 400 for an invalid payload', function invalidPayload() {
|
||||
return Promise.all([
|
||||
|
@ -23,8 +23,8 @@ define(function (require) {
|
|||
.send({
|
||||
input: {},
|
||||
processors: [{
|
||||
processorId: 'processor1',
|
||||
typeId: 'set',
|
||||
processor_id: 'processor1',
|
||||
type_id: 'set',
|
||||
value: 'bar'
|
||||
}]
|
||||
})
|
||||
|
@ -32,6 +32,26 @@ define(function (require) {
|
|||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return 200 for a valid simulate request', function validSetSimulate() {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send(testPipeline)
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
bdd.it('should enforce snake case', function setSimulateSnakeCase() {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
processors: [{
|
||||
processorId: 'processor1',
|
||||
typeId: 'set',
|
||||
targetField: 'foo',
|
||||
value: 'bar'
|
||||
}],
|
||||
input: {}
|
||||
})
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue