[Ingest pipelines] add support for ip type in convert processor (#100531)

* add ip option type to convert processor

* remove duped option

* small CR changes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Ignacio Rivas 2021-05-26 11:36:06 +02:00 committed by GitHub
parent 1f02c48d3c
commit 93acfb4d43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 131 additions and 0 deletions

View file

@ -0,0 +1,123 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { act } from 'react-dom/test-utils';
import { setup, SetupResult, getProcessorValue } from './processor.helpers';
// Default parameter values automatically added to the `convert processor` when saved
const defaultConvertParameters = {
if: undefined,
tag: undefined,
description: undefined,
target_field: undefined,
ignore_missing: undefined,
ignore_failure: undefined,
};
const CONVERT_TYPE = 'convert';
describe('Processor: Convert', () => {
let onUpdate: jest.Mock;
let testBed: SetupResult;
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
});
beforeEach(async () => {
onUpdate = jest.fn();
await act(async () => {
testBed = await setup({
value: {
processors: [],
},
onFlyoutOpen: jest.fn(),
onUpdate,
});
});
testBed.component.update();
// Open flyout to add new processor
testBed.actions.addProcessor();
// Add type (the other fields are not visible until a type is selected)
await testBed.actions.addProcessorType(CONVERT_TYPE);
});
test('prevents form submission if required fields are not provided', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;
// Click submit button with only the processor type defined
await saveNewProcessor();
// Expect form error as "field" and "type" are required parameters
expect(form.getErrorsMessages()).toEqual([
'A field value is required.',
'A type value is required.',
]);
});
test('saves with default parameter values', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;
// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');
// Add "type" value (required)
form.setSelectValue('typeSelectorField', 'ip');
// Save the field
await saveNewProcessor();
const processors = getProcessorValue(onUpdate, CONVERT_TYPE);
expect(processors[0][CONVERT_TYPE]).toEqual({
...defaultConvertParameters,
field: 'field_1',
type: 'ip',
});
});
test('allows optional parameters to be set', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;
// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');
// Add "type" value (required)
form.setSelectValue('typeSelectorField', 'ip');
// Set optional parameteres
form.setInputValue('targetField.input', 'target_field');
form.toggleEuiSwitch('ignoreMissingSwitch.input');
form.toggleEuiSwitch('ignoreFailureSwitch.input');
// Save the field with new changes
await saveNewProcessor();
const processors = getProcessorValue(onUpdate, CONVERT_TYPE);
expect(processors[0][CONVERT_TYPE]).toEqual({
...defaultConvertParameters,
type: 'ip',
field: 'field_1',
target_field: 'target_field',
ignore_failure: true,
ignore_missing: true,
});
});
});

View file

@ -143,6 +143,7 @@ type TestSubject =
| 'messageField.input'
| 'mockCodeEditor'
| 'tagField.input'
| 'typeSelectorField'
| 'ignoreMissingSwitch.input'
| 'ignoreFailureSwitch.input'
| 'ifField.textarea'

View file

@ -58,6 +58,7 @@ export const Convert: FunctionComponent = () => {
<UseField
componentProps={{
euiFieldProps: {
'data-test-subj': 'typeSelectorField',
options: [
{
value: 'integer',
@ -101,6 +102,12 @@ export const Convert: FunctionComponent = () => {
{ defaultMessage: 'Boolean' }
),
},
{
value: 'ip',
text: i18n.translate('xpack.ingestPipelines.pipelineEditor.convertForm.ipOption', {
defaultMessage: 'IP',
}),
},
{
value: 'auto',
text: i18n.translate(