-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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
- Loading branch information
Showing
9 changed files
with
161 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters