mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Remove LP deprecations (#76536)
* inline deprecations in kbn-test * remove LP deprecations * remove test * inline log call * remove unnecessary deprecations for the test config
This commit is contained in:
parent
c547a81cbc
commit
74499c48ec
17 changed files with 8 additions and 555 deletions
|
@ -21,7 +21,6 @@ import { ToolingLog } from '@kbn/dev-utils';
|
|||
import { defaultsDeep } from 'lodash';
|
||||
|
||||
import { Config } from './config';
|
||||
import { transformDeprecations } from './transform_deprecations';
|
||||
|
||||
const cache = new WeakMap();
|
||||
|
||||
|
@ -52,8 +51,7 @@ async function getSettingsFromFile(log: ToolingLog, path: string, settingOverrid
|
|||
await cache.get(configProvider)!
|
||||
);
|
||||
|
||||
const logDeprecation = (error: string | Error) => log.error(error);
|
||||
return transformDeprecations(settingsWithDefaults, logDeprecation);
|
||||
return settingsWithDefaults;
|
||||
}
|
||||
|
||||
export async function readConfigFile(log: ToolingLog, path: string, settingOverrides: any = {}) {
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
// @ts-ignore
|
||||
import { createTransform, Deprecations } from '../../../../../../src/legacy/deprecation';
|
||||
|
||||
type DeprecationTransformer = (
|
||||
settings: object,
|
||||
log: (msg: string) => void
|
||||
) => {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export const transformDeprecations: DeprecationTransformer = createTransform([
|
||||
Deprecations.unused('servers.webdriver'),
|
||||
]);
|
|
@ -217,34 +217,4 @@ describe('getUnusedConfigKeys', () => {
|
|||
})
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
describe('using deprecation', () => {
|
||||
it('should use the plugin deprecations provider', async () => {
|
||||
expect(
|
||||
await getUnusedConfigKeys({
|
||||
coreHandledConfigPaths: [],
|
||||
pluginSpecs: [
|
||||
({
|
||||
getDeprecationsProvider() {
|
||||
return async ({ rename }: any) => [rename('foo1', 'foo2')];
|
||||
},
|
||||
getConfigPrefix: () => 'foo',
|
||||
} as unknown) as LegacyPluginSpec,
|
||||
],
|
||||
disabledPluginSpecs: [],
|
||||
settings: {
|
||||
foo: {
|
||||
foo: 'dolly',
|
||||
foo1: 'bar',
|
||||
},
|
||||
},
|
||||
legacyConfig: getConfig({
|
||||
foo: {
|
||||
foo2: 'bar',
|
||||
},
|
||||
}),
|
||||
})
|
||||
).toEqual(['foo.foo']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,10 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { set } from '@elastic/safer-lodash-set';
|
||||
import { difference, get } from 'lodash';
|
||||
// @ts-expect-error
|
||||
import { getTransform } from '../../../../legacy/deprecation/index';
|
||||
import { difference } from 'lodash';
|
||||
import { unset } from '../../../../legacy/utils';
|
||||
import { getFlattenedObject } from '../../../utils';
|
||||
import { hasConfigPathIntersection } from '../../config';
|
||||
|
@ -41,21 +38,6 @@ export async function getUnusedConfigKeys({
|
|||
settings: LegacyVars;
|
||||
legacyConfig: LegacyConfig;
|
||||
}) {
|
||||
// transform deprecated plugin settings
|
||||
for (let i = 0; i < pluginSpecs.length; i++) {
|
||||
const spec = pluginSpecs[i];
|
||||
const transform = await getTransform(spec);
|
||||
const prefix = spec.getConfigPrefix();
|
||||
|
||||
// nested plugin prefixes (a.b) translate to nested objects
|
||||
const pluginSettings = get(settings, prefix);
|
||||
if (pluginSettings) {
|
||||
// flattened settings are expected to be converted to nested objects
|
||||
// a.b = true => { a: { b: true }}
|
||||
set(settings, prefix, transform(pluginSettings));
|
||||
}
|
||||
}
|
||||
|
||||
// remove config values from disabled plugins
|
||||
for (const spec of disabledPluginSpecs) {
|
||||
unset(settings, spec.getConfigPrefix());
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { createTransform } from '../create_transform';
|
||||
import expect from '@kbn/expect';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('deprecation', function () {
|
||||
describe('createTransform', function () {
|
||||
it(`doesn't modify settings parameter`, function () {
|
||||
const settings = {
|
||||
original: true,
|
||||
};
|
||||
const deprecations = [
|
||||
(settings) => {
|
||||
settings.original = false;
|
||||
},
|
||||
];
|
||||
createTransform(deprecations)(settings);
|
||||
expect(settings.original).to.be(true);
|
||||
});
|
||||
|
||||
it('calls single deprecation in array', function () {
|
||||
const deprecations = [sinon.spy()];
|
||||
createTransform(deprecations)({});
|
||||
expect(deprecations[0].calledOnce).to.be(true);
|
||||
});
|
||||
|
||||
it('calls multiple deprecations in array', function () {
|
||||
const deprecations = [sinon.spy(), sinon.spy()];
|
||||
createTransform(deprecations)({});
|
||||
expect(deprecations[0].calledOnce).to.be(true);
|
||||
expect(deprecations[1].calledOnce).to.be(true);
|
||||
});
|
||||
|
||||
it('passes log function to deprecation', function () {
|
||||
const deprecation = sinon.spy();
|
||||
const log = function () {};
|
||||
createTransform([deprecation])({}, log);
|
||||
expect(deprecation.args[0][1]).to.be(log);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { deepCloneWithBuffers as clone } from '../utils';
|
||||
import { forEach, noop } from 'lodash';
|
||||
|
||||
export function createTransform(deprecations) {
|
||||
return (settings, log = noop) => {
|
||||
const result = clone(settings);
|
||||
|
||||
forEach(deprecations, (deprecation) => {
|
||||
deprecation(result, log);
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { rename } from '../rename';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('deprecation/deprecations', function () {
|
||||
describe('rename', function () {
|
||||
it('should rename simple property', function () {
|
||||
const value = 'value';
|
||||
const settings = {
|
||||
before: value,
|
||||
};
|
||||
|
||||
rename('before', 'after')(settings);
|
||||
expect(settings.before).to.be(undefined);
|
||||
expect(settings.after).to.be(value);
|
||||
});
|
||||
|
||||
it('should rename nested property', function () {
|
||||
const value = 'value';
|
||||
const settings = {
|
||||
someObject: {
|
||||
before: value,
|
||||
},
|
||||
};
|
||||
|
||||
rename('someObject.before', 'someObject.after')(settings);
|
||||
expect(settings.someObject.before).to.be(undefined);
|
||||
expect(settings.someObject.after).to.be(value);
|
||||
});
|
||||
|
||||
it('should rename property, even when the value is null', function () {
|
||||
const value = null;
|
||||
const settings = {
|
||||
before: value,
|
||||
};
|
||||
|
||||
rename('before', 'after')(settings);
|
||||
expect(settings.before).to.be(undefined);
|
||||
expect(settings.after).to.be(null);
|
||||
});
|
||||
|
||||
it(`shouldn't log when a rename doesn't occur`, function () {
|
||||
const settings = {
|
||||
exists: true,
|
||||
};
|
||||
|
||||
const log = sinon.spy();
|
||||
rename('doesntExist', 'alsoDoesntExist')(settings, log);
|
||||
expect(log.called).to.be(false);
|
||||
});
|
||||
|
||||
it('should log when a rename does occur', function () {
|
||||
const settings = {
|
||||
exists: true,
|
||||
};
|
||||
|
||||
const log = sinon.spy();
|
||||
rename('exists', 'alsoExists')(settings, log);
|
||||
|
||||
expect(log.calledOnce).to.be(true);
|
||||
expect(log.args[0][0]).to.match(/exists.+deprecated/);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import sinon from 'sinon';
|
||||
import { unused } from '../unused';
|
||||
|
||||
describe('deprecation/deprecations', function () {
|
||||
describe('unused', function () {
|
||||
it('should remove unused setting', function () {
|
||||
const settings = {
|
||||
old: true,
|
||||
};
|
||||
|
||||
unused('old')(settings);
|
||||
expect(settings.old).to.be(undefined);
|
||||
});
|
||||
|
||||
it(`shouldn't remove used setting`, function () {
|
||||
const value = 'value';
|
||||
const settings = {
|
||||
new: value,
|
||||
};
|
||||
|
||||
unused('old')(settings);
|
||||
expect(settings.new).to.be(value);
|
||||
});
|
||||
|
||||
it('should remove unused setting, even when null', function () {
|
||||
const settings = {
|
||||
old: null,
|
||||
};
|
||||
|
||||
unused('old')(settings);
|
||||
expect(settings.old).to.be(undefined);
|
||||
});
|
||||
|
||||
it('should log when removing unused setting', function () {
|
||||
const settings = {
|
||||
old: true,
|
||||
};
|
||||
|
||||
const log = sinon.spy();
|
||||
unused('old')(settings, log);
|
||||
|
||||
expect(log.calledOnce).to.be(true);
|
||||
expect(log.args[0][0]).to.match(/old.+deprecated/);
|
||||
});
|
||||
|
||||
it(`shouldn't log when no setting is unused`, function () {
|
||||
const settings = {
|
||||
new: true,
|
||||
};
|
||||
|
||||
const log = sinon.spy();
|
||||
unused('old')(settings, log);
|
||||
expect(log.called).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
export { rename } from './rename';
|
||||
export { unused } from './unused';
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { set } from '@elastic/safer-lodash-set';
|
||||
import { get, isUndefined, noop } from 'lodash';
|
||||
import { unset } from '../../utils';
|
||||
|
||||
export function rename(oldKey, newKey) {
|
||||
return (settings, log = noop) => {
|
||||
const value = get(settings, oldKey);
|
||||
if (isUndefined(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset(settings, oldKey);
|
||||
set(settings, newKey, value);
|
||||
|
||||
log(`Config key "${oldKey}" is deprecated. It has been replaced with "${newKey}"`);
|
||||
};
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { get, isUndefined, noop } from 'lodash';
|
||||
import { unset } from '../../utils';
|
||||
|
||||
export function unused(oldKey) {
|
||||
return (settings, log = noop) => {
|
||||
const value = get(settings, oldKey);
|
||||
if (isUndefined(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset(settings, oldKey);
|
||||
log(`${oldKey} is deprecated and is no longer used`);
|
||||
};
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { noop } from 'lodash';
|
||||
|
||||
import { createTransform } from './create_transform';
|
||||
import { rename, unused } from './deprecations';
|
||||
|
||||
export async function getTransform(spec) {
|
||||
const deprecationsProvider = spec.getDeprecationsProvider() || noop;
|
||||
if (!deprecationsProvider) return;
|
||||
const transforms = (await deprecationsProvider({ rename, unused })) || [];
|
||||
return createTransform(transforms);
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { rename, unused } from './deprecations';
|
||||
|
||||
export { createTransform } from './create_transform';
|
||||
export { getTransform } from './get_transform';
|
||||
export const Deprecations = { rename, unused };
|
|
@ -45,10 +45,6 @@ describe('plugin discovery/extend config service', () => {
|
|||
enabled: Joi.boolean().default(true),
|
||||
test: Joi.string().default('bonk'),
|
||||
}).default(),
|
||||
|
||||
deprecations({ rename }) {
|
||||
return [rename('oldTest', 'test')];
|
||||
},
|
||||
}),
|
||||
})
|
||||
.getPluginSpecs()
|
||||
|
@ -74,16 +70,14 @@ describe('plugin discovery/extend config service', () => {
|
|||
getConfigPrefix: sandbox.stub().returns(configPrefix),
|
||||
};
|
||||
|
||||
const logDeprecation = sandbox.stub();
|
||||
|
||||
const getSettings = sandbox.stub(SettingsNS, 'getSettings').returns(rootSettings.foo.bar);
|
||||
|
||||
const getSchema = sandbox.stub(SchemaNS, 'getSchema').returns(schema);
|
||||
|
||||
await extendConfigService(pluginSpec, config, rootSettings, logDeprecation);
|
||||
await extendConfigService(pluginSpec, config, rootSettings);
|
||||
|
||||
sinon.assert.calledOnce(getSettings);
|
||||
sinon.assert.calledWithExactly(getSettings, pluginSpec, rootSettings, logDeprecation);
|
||||
sinon.assert.calledWithExactly(getSettings, pluginSpec, rootSettings);
|
||||
|
||||
sinon.assert.calledOnce(getSchema);
|
||||
sinon.assert.calledWithExactly(getSchema, pluginSpec);
|
||||
|
@ -145,41 +139,6 @@ describe('plugin discovery/extend config service', () => {
|
|||
expect(error.message).to.contain('"test" must be a string');
|
||||
}
|
||||
});
|
||||
|
||||
it('calls logDeprecation() with deprecation messages', async () => {
|
||||
const config = Config.withDefaultSchema();
|
||||
const logDeprecation = sinon.stub();
|
||||
await extendConfigService(
|
||||
pluginSpec,
|
||||
config,
|
||||
{
|
||||
foo: {
|
||||
bar: {
|
||||
baz: {
|
||||
oldTest: '123',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
logDeprecation
|
||||
);
|
||||
sinon.assert.calledOnce(logDeprecation);
|
||||
sinon.assert.calledWithExactly(logDeprecation, sinon.match('"oldTest" is deprecated'));
|
||||
});
|
||||
|
||||
it('uses settings after transforming deprecations', async () => {
|
||||
const config = Config.withDefaultSchema();
|
||||
await extendConfigService(pluginSpec, config, {
|
||||
foo: {
|
||||
bar: {
|
||||
baz: {
|
||||
oldTest: '123',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(config.get('foo.bar.baz.test')).to.be('123');
|
||||
});
|
||||
});
|
||||
|
||||
describe('disableConfigExtension()', () => {
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import { PluginPack } from '../../plugin_pack';
|
||||
import { getSettings } from '../settings';
|
||||
|
@ -33,7 +32,6 @@ describe('plugin_discovery/settings', () => {
|
|||
provider: ({ Plugin }) =>
|
||||
new Plugin({
|
||||
configPrefix: 'a.b.c',
|
||||
deprecations: ({ rename }) => [rename('foo', 'bar')],
|
||||
}),
|
||||
})
|
||||
.getPluginSpecs()
|
||||
|
@ -59,28 +57,5 @@ describe('plugin_discovery/settings', () => {
|
|||
it('allows rootSettings to be undefined', async () => {
|
||||
expect(await getSettings(pluginSpec)).to.eql(undefined);
|
||||
});
|
||||
|
||||
it('resolves deprecations', async () => {
|
||||
const logDeprecation = sinon.stub();
|
||||
expect(
|
||||
await getSettings(
|
||||
pluginSpec,
|
||||
{
|
||||
a: {
|
||||
b: {
|
||||
c: {
|
||||
foo: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
logDeprecation
|
||||
)
|
||||
).to.eql({
|
||||
bar: true,
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(logDeprecation);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,8 +30,8 @@ import { getSchema, getStubSchema } from './schema';
|
|||
* @param {Function} [logDeprecation]
|
||||
* @return {Promise<undefined>}
|
||||
*/
|
||||
export async function extendConfigService(spec, config, rootSettings, logDeprecation) {
|
||||
const settings = await getSettings(spec, rootSettings, logDeprecation);
|
||||
export async function extendConfigService(spec, config, rootSettings) {
|
||||
const settings = await getSettings(spec, rootSettings);
|
||||
const schema = await getSchema(spec);
|
||||
config.extendSchema(schema, settings, spec.getConfigPrefix());
|
||||
}
|
||||
|
|
|
@ -19,20 +19,16 @@
|
|||
|
||||
import { get } from 'lodash';
|
||||
|
||||
import { getTransform } from '../../deprecation';
|
||||
|
||||
/**
|
||||
* Get the settings for a pluginSpec from the raw root settings while
|
||||
* optionally calling logDeprecation() with warnings about deprecated
|
||||
* settings that were used
|
||||
* @param {PluginSpec} spec
|
||||
* @param {Object} rootSettings
|
||||
* @param {Function} [logDeprecation]
|
||||
* @return {Promise<Object>}
|
||||
*/
|
||||
export async function getSettings(spec, rootSettings, logDeprecation) {
|
||||
export async function getSettings(spec, rootSettings) {
|
||||
const prefix = spec.getConfigPrefix();
|
||||
const rawSettings = get(rootSettings, prefix);
|
||||
const transform = await getTransform(spec);
|
||||
return transform(rawSettings, logDeprecation);
|
||||
return rawSettings;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue