Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 type defined
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved
await saveNewProcessor();

// Expect form error as "field" is required parameter
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved
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