From 5112efc121f9ad1e9ffe07a8f278c794c2ac39a0 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Fri, 15 Oct 2021 10:46:46 -0500 Subject: [PATCH] Add unit test for source config deprecations --- .../plugins/infra/server/deprecations.test.ts | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 x-pack/plugins/infra/server/deprecations.test.ts diff --git a/x-pack/plugins/infra/server/deprecations.test.ts b/x-pack/plugins/infra/server/deprecations.test.ts new file mode 100644 index 0000000000000..318f1e50d6662 --- /dev/null +++ b/x-pack/plugins/infra/server/deprecations.test.ts @@ -0,0 +1,86 @@ +/* + * 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 { getInfraDeprecationsFactory } from './deprecations'; + +describe('Infra plugin deprecations', () => { + describe('Source configuration deprecations', () => { + test('returns no deprecations when all fields are set to the default values', async () => { + const sources = { + getAllSourceConfigurations: () => [ + { + configuration: { + name: 'Default', + fields: { + timestamp: '@timestamp', + tiebreaker: '_doc', + container: 'container.id', + host: 'host.name', + pod: 'kubernetes.pod.uid', + }, + }, + }, + { + configuration: { + name: 'Alternate', + fields: { + timestamp: '@timestamp', + tiebreaker: '_doc', + container: 'container.id', + host: 'host.name', + pod: 'kubernetes.pod.uid', + }, + }, + }, + ], + }; + const getDeprecations = getInfraDeprecationsFactory(sources as any); + const deprecations = await getDeprecations({} as any); + expect(deprecations.length).toBe(0); + }); + }); + test('returns expected deprecations when some fields are not set to default values in one or more source configurations', async () => { + const sources = { + getAllSourceConfigurations: () => [ + { + configuration: { + name: 'Default', + fields: { + timestamp: 'not-@timestamp', + tiebreaker: '_doc', + container: 'not-container.id', + host: 'host.name', + pod: 'not-kubernetes.pod.uid', + }, + }, + }, + { + configuration: { + name: 'Alternate', + fields: { + timestamp: 'not-@timestamp', + tiebreaker: 'not-_doc', + container: 'container.id', + host: 'not-host.name', + pod: 'kubernetes.pod.uid', + }, + }, + }, + ], + }; + const getDeprecations = getInfraDeprecationsFactory(sources as any); + const deprecations = await getDeprecations({} as any); + expect(deprecations.length).toBe(5); + expect( + deprecations.map((d) => + d.title.replace(/Source configuration field "(.*)" is deprecated./, '$1') + ) + ).toEqual( + expect.arrayContaining(['timestamp', 'tiebreaker', 'container ID', 'host name', 'pod ID']) + ); + }); +});