From 84a6eac8ce2f57718f5cc7c60a00e9ba7f8ba361 Mon Sep 17 00:00:00 2001 From: mgiota Date: Fri, 3 Dec 2021 13:33:08 +0100 Subject: [PATCH] resource installer attempt --- .../resource_installer.mock.ts | 2 +- .../rule_data_plugin_service.test.ts | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.mock.ts b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.mock.ts index 277befacea662..0b3940b936424 100644 --- a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.mock.ts +++ b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.mock.ts @@ -11,7 +11,7 @@ type Schema = PublicMethodsOf; export type ResourceInstallerMock = jest.Mocked; const createResourceInstallerMock = () => { return { - installCommonResources: jest.fn(() => Promise.resolve()), + installCommonResources: jest.fn(), installIndexLevelResources: jest.fn(), installAndUpdateNamespaceLevelResources: jest.fn(), }; diff --git a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.test.ts b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.test.ts index b939be0d191a4..094e63b738180 100644 --- a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.test.ts +++ b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/rule_data_plugin_service.test.ts @@ -11,10 +11,15 @@ import { elasticsearchServiceMock } from 'src/core/server/mocks'; import { AlertConsumers } from '@kbn/rule-data-utils/alerts_as_data_rbac'; import { Dataset } from './index_options'; import { RuleDataClient } from '../rule_data_client/rule_data_client'; +import { ResourceInstaller } from './resource_installer'; +import { resourceInstallerMock as mockResourceInstaller } from './resource_installer.mock'; import { createRuleDataClientMock as mockCreateRuleDataClient } from '../rule_data_client/rule_data_client.mock'; jest.mock('../rule_data_client/rule_data_client', () => ({ RuleDataClient: jest.fn().mockImplementation(() => mockCreateRuleDataClient()), })); +jest.mock('./resource_installer', () => ({ + ResourceInstaller: jest.fn().mockImplementation(() => mockResourceInstaller.create()), +})); describe('ruleDataPluginService', () => { beforeEach(() => { @@ -71,6 +76,24 @@ describe('ruleDataPluginService', () => { }); }); + describe('initializeService', () => { + it('calls ResourceInstaller', async () => { + const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient(); + const getClusterClient = jest.fn(() => Promise.resolve(mockClusterClient)); + + new RuleDataService({ + logger: loggerMock.create(), + getClusterClient, + kibanaVersion: '8.1.0', + isWriteEnabled: true, + disabledRegistrationContexts: ['observability.logs'], + isWriterCacheEnabled: true, + }); + + expect(ResourceInstaller).toHaveBeenCalled(); + }); + }); + describe('initializeIndex', () => { it('calls RuleDataClient', async () => { const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient();