mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 10:23:14 -04:00
Expressions/migrations2 (#81281)
This commit is contained in:
parent
4f717708b4
commit
076bb734c7
20 changed files with 296 additions and 7 deletions
|
@ -22,6 +22,7 @@ import * as expressionTypes from '../expression_types';
|
|||
import * as expressionFunctions from '../expression_functions';
|
||||
import { Execution } from '../execution';
|
||||
import { ExpressionAstFunction, parseExpression } from '../ast';
|
||||
import { MigrateFunction } from '../../../kibana_utils/common/persistable_state';
|
||||
|
||||
describe('Executor', () => {
|
||||
test('can instantiate', () => {
|
||||
|
@ -158,6 +159,7 @@ describe('Executor', () => {
|
|||
|
||||
const injectFn = jest.fn().mockImplementation((args, references) => args);
|
||||
const extractFn = jest.fn().mockReturnValue({ args: {}, references: [] });
|
||||
const migrateFn = jest.fn().mockImplementation((args) => args);
|
||||
|
||||
const fooFn = {
|
||||
name: 'foo',
|
||||
|
@ -174,6 +176,14 @@ describe('Executor', () => {
|
|||
inject: (state: ExpressionAstFunction['arguments']) => {
|
||||
return injectFn(state);
|
||||
},
|
||||
migrations: {
|
||||
'7.10.0': (((state: ExpressionAstFunction, version: string): ExpressionAstFunction => {
|
||||
return migrateFn(state, version);
|
||||
}) as any) as MigrateFunction,
|
||||
'7.10.1': (((state: ExpressionAstFunction, version: string): ExpressionAstFunction => {
|
||||
return migrateFn(state, version);
|
||||
}) as any) as MigrateFunction,
|
||||
},
|
||||
fn: jest.fn(),
|
||||
};
|
||||
executor.registerFunction(fooFn);
|
||||
|
@ -194,5 +204,26 @@ describe('Executor', () => {
|
|||
expect(extractFn).toBeCalledTimes(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.migrate', () => {
|
||||
test('calls migrate function for every expression function in expression', () => {
|
||||
executor.migrate(
|
||||
parseExpression('foo bar="baz" | foo bar={foo bar="baz" | foo bar={foo bar="baz"}}'),
|
||||
'7.10.0'
|
||||
);
|
||||
expect(migrateFn).toBeCalledTimes(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.migrateToLatest', () => {
|
||||
test('calls extract function for every expression function in expression', () => {
|
||||
migrateFn.mockClear();
|
||||
executor.migrateToLatest(
|
||||
parseExpression('foo bar="baz" | foo bar={foo bar="baz" | foo bar={foo bar="baz"}}'),
|
||||
'7.10.0'
|
||||
);
|
||||
expect(migrateFn).toBeCalledTimes(10);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue