Skip to content

Commit

Permalink
[Ingest pipelines] add support for ip type in convert processor (elas…
Browse files Browse the repository at this point in the history
…tic#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>
  • Loading branch information
2 people authored and ecezalp committed May 26, 2021
1 parent 4d9a30a commit c6dbb8d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type TestSubject =
| 'messageField.input'
| 'mockCodeEditor'
| 'tagField.input'
| 'typeSelectorField'
| 'ignoreMissingSwitch.input'
| 'ignoreFailureSwitch.input'
| 'ifField.textarea'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const Convert: FunctionComponent = () => {
<UseField
componentProps={{
euiFieldProps: {
'data-test-subj': 'typeSelectorField',
options: [
{
value: 'integer',
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c6dbb8d

Please sign in to comment.