From 129bd23852f7d31141d34f7d241dc98cdc60a9ef Mon Sep 17 00:00:00 2001 From: Sam Robson Date: Mon, 13 Sep 2021 11:36:48 +0100 Subject: [PATCH] test: clientOptions config accessed but not required Signed-off-by: Sam Robson --- .../engines/ElasticSearchSearchEngine.test.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts index 36fb2e56c6..2877632013 100644 --- a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts +++ b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts @@ -24,6 +24,7 @@ import { ElasticSearchSearchEngine, encodePageCursor, } from './ElasticSearchSearchEngine'; +import { ConfigReader } from '@backstage/config'; class ElasticSearchSearchEngineForTranslatorTests extends ElasticSearchSearchEngine { getTranslator() { @@ -558,6 +559,55 @@ describe('ElasticSearchSearchEngine', () => { ]); }); }); + + describe('ElasticSearchSearchEngine.fromConfig', () => { + it('accesses the clientOptions config', async () => { + const esOptions = { + clientOptions: { + ssl: { + rejectUnauthorized: true, + }, + }, + node: 'http://test-node', + auth: { + apiKey: 'key', + }, + }; + + const config = new ConfigReader({}); + const esConfig = new ConfigReader(esOptions); + jest.spyOn(config, 'getConfig').mockImplementation(() => esConfig); + const getOptionalConfig = jest.spyOn(esConfig, 'getOptionalConfig'); + + await ElasticSearchSearchEngine.fromConfig({ + logger: getVoidLogger(), + config, + }); + + expect(getOptionalConfig.mock.calls[0][0]).toEqual('clientOptions'); + }); + + it('does not require the clientOptions config', async () => { + const config = new ConfigReader({ + search: { + elasticsearch: { + node: 'http://test-node', + auth: { + apiKey: 'test-key', + }, + }, + }, + }); + + expect( + async () => + await ElasticSearchSearchEngine.fromConfig({ + logger: getVoidLogger(), + config, + }), + ).not.toThrowError(); + }); + }); }); describe('decodePageCursor', () => {