Skip to content

Commit

Permalink
Add unit test for source config deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Oct 15, 2021
1 parent a30ebb6 commit 5112efc
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions x-pack/plugins/infra/server/deprecations.test.ts
Original file line number Diff line number Diff line change
@@ -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'])
);
});
});

0 comments on commit 5112efc

Please sign in to comment.