|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { ensureValidConfiguration } from './ensure_valid_configuration'; |
| 21 | +import { getUnusedConfigKeys } from './get_unused_config_keys'; |
| 22 | +import { configServiceMock } from '../../config/config_service.mock'; |
| 23 | + |
| 24 | +jest.mock('./get_unused_config_keys'); |
| 25 | + |
| 26 | +describe('ensureValidConfiguration', () => { |
| 27 | + let configService: ReturnType<typeof configServiceMock.create>; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + jest.clearAllMocks(); |
| 31 | + configService = configServiceMock.create(); |
| 32 | + configService.getUsedPaths.mockReturnValue(Promise.resolve(['core', 'elastic'])); |
| 33 | + |
| 34 | + (getUnusedConfigKeys as any).mockImplementation(() => []); |
| 35 | + }); |
| 36 | + |
| 37 | + it('calls getUnusedConfigKeys with correct parameters', async () => { |
| 38 | + await ensureValidConfiguration( |
| 39 | + configService as any, |
| 40 | + { |
| 41 | + settings: 'settings', |
| 42 | + pluginSpecs: 'pluginSpecs', |
| 43 | + disabledPluginSpecs: 'disabledPluginSpecs', |
| 44 | + pluginExtendedConfig: 'pluginExtendedConfig', |
| 45 | + uiExports: 'uiExports', |
| 46 | + } as any |
| 47 | + ); |
| 48 | + expect(getUnusedConfigKeys).toHaveBeenCalledTimes(1); |
| 49 | + expect(getUnusedConfigKeys).toHaveBeenCalledWith({ |
| 50 | + coreHandledConfigPaths: ['core', 'elastic'], |
| 51 | + pluginSpecs: 'pluginSpecs', |
| 52 | + disabledPluginSpecs: 'disabledPluginSpecs', |
| 53 | + inputSettings: 'settings', |
| 54 | + legacyConfig: 'pluginExtendedConfig', |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + it('returns normally when there is no unused keys', async () => { |
| 59 | + await expect( |
| 60 | + ensureValidConfiguration(configService as any, {} as any) |
| 61 | + ).resolves.toBeUndefined(); |
| 62 | + |
| 63 | + expect(getUnusedConfigKeys).toHaveBeenCalledTimes(1); |
| 64 | + }); |
| 65 | + |
| 66 | + it('throws when there are some unused keys', async () => { |
| 67 | + (getUnusedConfigKeys as any).mockImplementation(() => ['some.key', 'some.other.key']); |
| 68 | + |
| 69 | + await expect( |
| 70 | + ensureValidConfiguration(configService as any, {} as any) |
| 71 | + ).rejects.toMatchInlineSnapshot( |
| 72 | + `[Error: Unknown configuration key(s): "some.key", "some.other.key". Check for spelling errors and ensure that expected plugins are installed.]` |
| 73 | + ); |
| 74 | + }); |
| 75 | +}); |
0 commit comments