Expressions/migrations2 (#81281)

This commit is contained in:
Peter Pisljar 2020-10-30 06:01:45 +01:00 committed by GitHub
parent 4f717708b4
commit 076bb734c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 296 additions and 7 deletions

View file

@ -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);
});
});
});
});