move oss features registration to KP (#66524)

* register OSS features with KP SO types only

* use Licensing plugin API in features plugin

* add plugin tests

* filter hidden types out

* cleanup tests

* rename

* add degug logging

* add warning for setup contract

* fix typo
This commit is contained in:
Mikhail Shustov 2020-05-15 20:01:33 +02:00 committed by GitHub
parent 4e0921d41e
commit 915ff5db50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 70 deletions

View file

@ -0,0 +1,97 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { coreMock, savedObjectsServiceMock } from 'src/core/server/mocks';
import { Plugin } from './plugin';
const initContext = coreMock.createPluginInitializerContext();
const coreSetup = coreMock.createSetup();
const coreStart = coreMock.createStart();
const typeRegistry = savedObjectsServiceMock.createTypeRegistryMock();
typeRegistry.getAllTypes.mockReturnValue([
{
name: 'foo',
hidden: false,
mappings: { properties: {} },
namespaceType: 'single' as 'single',
},
{
name: 'bar',
hidden: true,
mappings: { properties: {} },
namespaceType: 'agnostic' as 'agnostic',
},
]);
coreStart.savedObjects.getTypeRegistry.mockReturnValue(typeRegistry);
describe('Features Plugin', () => {
it('returns OSS + registered features', async () => {
const plugin = new Plugin(initContext);
const { registerFeature } = await plugin.setup(coreSetup, {});
registerFeature({
id: 'baz',
name: 'baz',
app: [],
privileges: null,
});
const { getFeatures } = await plugin.start(coreStart);
expect(getFeatures().map(f => f.id)).toMatchInlineSnapshot(`
Array [
"baz",
"discover",
"visualize",
"dashboard",
"dev_tools",
"advancedSettings",
"indexPatterns",
"savedObjectsManagement",
]
`);
});
it('returns OSS + registered features with timelion when available', async () => {
const plugin = new Plugin(initContext);
const { registerFeature } = await plugin.setup(coreSetup, {
visTypeTimelion: { uiEnabled: true },
});
registerFeature({
id: 'baz',
name: 'baz',
app: [],
privileges: null,
});
const { getFeatures } = await plugin.start(coreStart);
expect(getFeatures().map(f => f.id)).toMatchInlineSnapshot(`
Array [
"baz",
"discover",
"visualize",
"dashboard",
"dev_tools",
"advancedSettings",
"indexPatterns",
"savedObjectsManagement",
"timelion",
]
`);
});
it('registers not hidden saved objects types', async () => {
const plugin = new Plugin(initContext);
await plugin.setup(coreSetup, {});
const { getFeatures } = await plugin.start(coreStart);
const soTypes =
getFeatures().find(f => f.id === 'savedObjectsManagement')?.privileges?.all.savedObject.all ||
[];
expect(soTypes.includes('foo')).toBe(true);
expect(soTypes.includes('bar')).toBe(false);
});
});