mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
## Summary Passing default solution from cloud onboarding process. 1. Renaming. Solution changes are not released yet, would be shipped with `8.15`, so it's fine to do it. - `search` -> `es` - `observability` -> `oblt` - Adjusted telemetry accordingly 2. Added `cloud` as optional dependency to `spaces` plugin to use `onboarding.defaultSolution` passed through setup contract. ### How to test 1. Set `xpack.cloud.onboarding.default_solution` to `es | oblt | security` 2. Check that default space was created with provided solution `GET kbn:/api/spaces/space/default` ### Checklist - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) __Fixes: https://github.com/elastic/kibana/issues/184999__ --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
174 lines
6.9 KiB
TypeScript
174 lines
6.9 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
* 2.0.
|
|
*/
|
|
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
|
import { cloudMock } from '@kbn/cloud-plugin/public/mocks';
|
|
import type { CloudSetup } from '@kbn/cloud-plugin/server';
|
|
import type { CoreSetup } from '@kbn/core/server';
|
|
import { coreMock } from '@kbn/core/server/mocks';
|
|
import { featuresPluginMock } from '@kbn/features-plugin/server/mocks';
|
|
import { licensingMock } from '@kbn/licensing-plugin/server/mocks';
|
|
import { usageCollectionPluginMock } from '@kbn/usage-collection-plugin/server/mocks';
|
|
|
|
import { createDefaultSpace } from './default_space/create_default_space';
|
|
import type { PluginsStart } from './plugin';
|
|
import { SpacesPlugin } from './plugin';
|
|
|
|
jest.mock('./default_space/create_default_space');
|
|
|
|
describe('Spaces plugin', () => {
|
|
describe('#setup', () => {
|
|
it('can setup with all optional plugins disabled, exposing the expected contract', () => {
|
|
const initializerContext = coreMock.createPluginInitializerContext({});
|
|
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
|
|
const features = featuresPluginMock.createSetup();
|
|
const licensing = licensingMock.createSetup();
|
|
|
|
const plugin = new SpacesPlugin(initializerContext);
|
|
const spacesSetup = plugin.setup(core, { features, licensing });
|
|
expect(spacesSetup).toMatchInlineSnapshot(`
|
|
Object {
|
|
"hasOnlyDefaultSpace$": Observable {
|
|
"operator": [Function],
|
|
"source": Observable {
|
|
"_subscribe": [Function],
|
|
},
|
|
},
|
|
"spacesClient": Object {
|
|
"registerClientWrapper": [Function],
|
|
"setClientRepositoryFactory": [Function],
|
|
},
|
|
"spacesService": Object {
|
|
"getSpaceId": [Function],
|
|
"namespaceToSpaceId": [Function],
|
|
"spaceIdToNamespace": [Function],
|
|
},
|
|
}
|
|
`);
|
|
});
|
|
|
|
// Joe removed this test, but we're not sure why...
|
|
it('registers the capabilities provider and switcher', () => {
|
|
const initializerContext = coreMock.createPluginInitializerContext({});
|
|
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
|
|
const features = featuresPluginMock.createSetup();
|
|
const licensing = licensingMock.createSetup();
|
|
|
|
const plugin = new SpacesPlugin(initializerContext);
|
|
|
|
plugin.setup(core, { features, licensing });
|
|
|
|
expect(core.capabilities.registerProvider).toHaveBeenCalledTimes(1);
|
|
expect(core.capabilities.registerSwitcher).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('registers the usage collector if the usageCollection plugin is enabled', () => {
|
|
const initializerContext = coreMock.createPluginInitializerContext({});
|
|
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
|
|
const features = featuresPluginMock.createSetup();
|
|
const licensing = licensingMock.createSetup();
|
|
|
|
const usageCollection = usageCollectionPluginMock.createSetupContract();
|
|
|
|
const plugin = new SpacesPlugin(initializerContext);
|
|
|
|
plugin.setup(core, { features, licensing, usageCollection });
|
|
|
|
expect(usageCollection.getCollectorByType('spaces')).toBeDefined();
|
|
});
|
|
|
|
it('can setup space with default solution', async () => {
|
|
const initializerContext = coreMock.createPluginInitializerContext({ maxSpaces: 1000 });
|
|
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
|
|
const features = featuresPluginMock.createSetup();
|
|
const licensing = licensingMock.createSetup();
|
|
const cloud = {
|
|
...cloudMock.createSetup(),
|
|
apm: {},
|
|
onboarding: { defaultSolution: 'security' },
|
|
} as CloudSetup;
|
|
|
|
const plugin = new SpacesPlugin(initializerContext);
|
|
plugin.setup(core, { features, licensing, cloud });
|
|
|
|
expect(createDefaultSpace).toHaveBeenCalledWith(
|
|
expect.objectContaining({ solution: 'security' })
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('#start', () => {
|
|
it('can start with all optional plugins disabled, exposing the expected contract', () => {
|
|
const initializerContext = coreMock.createPluginInitializerContext({});
|
|
const coreSetup = coreMock.createSetup() as CoreSetup<PluginsStart>;
|
|
const features = featuresPluginMock.createSetup();
|
|
const licensing = licensingMock.createSetup();
|
|
|
|
const plugin = new SpacesPlugin(initializerContext);
|
|
plugin.setup(coreSetup, { features, licensing });
|
|
|
|
const coreStart = coreMock.createStart();
|
|
|
|
const spacesStart = plugin.start(coreStart);
|
|
expect(spacesStart).toMatchInlineSnapshot(`
|
|
Object {
|
|
"hasOnlyDefaultSpace$": Observable {
|
|
"operator": [Function],
|
|
"source": Observable {
|
|
"_subscribe": [Function],
|
|
},
|
|
},
|
|
"spacesService": Object {
|
|
"createSpacesClient": [Function],
|
|
"getActiveSpace": [Function],
|
|
"getSpaceId": [Function],
|
|
"isInDefaultSpace": [Function],
|
|
"namespaceToSpaceId": [Function],
|
|
"spaceIdToNamespace": [Function],
|
|
},
|
|
}
|
|
`);
|
|
});
|
|
});
|
|
|
|
it('determines hasOnlyDefaultSpace$ correctly when maxSpaces=1', async () => {
|
|
const initializerContext = coreMock.createPluginInitializerContext({ maxSpaces: 1 });
|
|
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
|
|
const features = featuresPluginMock.createSetup();
|
|
const licensing = licensingMock.createSetup();
|
|
|
|
const usageCollection = usageCollectionPluginMock.createSetupContract();
|
|
|
|
const plugin = new SpacesPlugin(initializerContext);
|
|
|
|
const spacesSetup = plugin.setup(core, { features, licensing, usageCollection });
|
|
const coreStart = coreMock.createStart();
|
|
const spacesStart = plugin.start(coreStart);
|
|
|
|
await expect(lastValueFrom(spacesSetup.hasOnlyDefaultSpace$)).resolves.toEqual(true);
|
|
await expect(lastValueFrom(spacesStart.hasOnlyDefaultSpace$)).resolves.toEqual(true);
|
|
});
|
|
|
|
it('determines hasOnlyDefaultSpace$ correctly when maxSpaces=1000', async () => {
|
|
const initializerContext = coreMock.createPluginInitializerContext({ maxSpaces: 1000 });
|
|
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
|
|
const features = featuresPluginMock.createSetup();
|
|
const licensing = licensingMock.createSetup();
|
|
|
|
const usageCollection = usageCollectionPluginMock.createSetupContract();
|
|
|
|
const plugin = new SpacesPlugin(initializerContext);
|
|
|
|
const spacesSetup = plugin.setup(core, { features, licensing, usageCollection });
|
|
const coreStart = coreMock.createStart();
|
|
const spacesStart = plugin.start(coreStart);
|
|
|
|
await expect(lastValueFrom(spacesSetup.hasOnlyDefaultSpace$)).resolves.toEqual(false);
|
|
await expect(lastValueFrom(spacesStart.hasOnlyDefaultSpace$)).resolves.toEqual(false);
|
|
});
|
|
});
|