Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Aug 12, 2021
1 parent 6562737 commit 87cf604
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 18 deletions.
42 changes: 42 additions & 0 deletions x-pack/plugins/actions/server/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { config } from './index';
import { applyDeprecations, configDeprecationFactory } from '@kbn/config';

const CONFIG_PATH = 'xpack.actions';
const applyStackAlertDeprecations = (settings: Record<string, unknown> = {}) => {
const deprecations = config.deprecations!(configDeprecationFactory);
const deprecationMessages: string[] = [];
const _config = {
[CONFIG_PATH]: settings,
};
const { config: migrated } = applyDeprecations(
_config,
deprecations.map((deprecation) => ({
deprecation,
path: CONFIG_PATH,
})),
() => ({ message }) => deprecationMessages.push(message)
);
return {
messages: deprecationMessages,
migrated,
};
};

describe('index', () => {
describe('deprecations', () => {
it('should deprecate .enabled flag', () => {
const { messages } = applyStackAlertDeprecations({ enabled: false });
expect(messages).toMatchInlineSnapshot(`
Array [
"\\"xpack.actions.enabled\\" is deprecated. The ability to disable this plugin will be removed in 8.0.0.",
]
`);
});
});
});
17 changes: 9 additions & 8 deletions x-pack/plugins/actions/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { get } from 'lodash';
import type { PublicMethodsOf } from '@kbn/utility-types';
import { PluginInitializerContext, PluginConfigDescriptor } from '../../../../src/core/server';
import { ActionsPlugin } from './plugin';
Expand Down Expand Up @@ -59,7 +59,8 @@ export const config: PluginConfigDescriptor<ActionsConfig> = {
deprecations: ({ renameFromRoot, unused }) => [
renameFromRoot('xpack.actions.whitelistedHosts', 'xpack.actions.allowedHosts'),
(settings, fromPath, addDeprecation) => {
const customHostSettings = settings?.xpack?.actions?.customHostSettings ?? [];
const actions = get(settings, fromPath);
const customHostSettings = actions?.customHostSettings ?? [];
if (
customHostSettings.find(
(customHostSchema: CustomHostSettings) =>
Expand All @@ -84,7 +85,8 @@ export const config: PluginConfigDescriptor<ActionsConfig> = {
}
},
(settings, fromPath, addDeprecation) => {
if (!!settings?.xpack?.actions?.rejectUnauthorized) {
const actions = get(settings, fromPath);
if (!!actions?.rejectUnauthorized) {
addDeprecation({
message:
`"xpack.actions.rejectUnauthorized" is deprecated. Use "xpack.actions.verificationMode" instead, ` +
Expand All @@ -102,7 +104,8 @@ export const config: PluginConfigDescriptor<ActionsConfig> = {
}
},
(settings, fromPath, addDeprecation) => {
if (!!settings?.xpack?.actions?.proxyRejectUnauthorizedCertificates) {
const actions = get(settings, fromPath);
if (!!actions?.proxyRejectUnauthorizedCertificates) {
addDeprecation({
message:
`"xpack.actions.proxyRejectUnauthorizedCertificates" is deprecated. Use "xpack.actions.proxyVerificationMode" instead, ` +
Expand All @@ -120,10 +123,8 @@ export const config: PluginConfigDescriptor<ActionsConfig> = {
}
},
(settings, fromPath, addDeprecation) => {
if (
settings?.xpack?.actions?.enabled === false ||
settings?.xpack?.actions?.enabled === true
) {
const actions = get(settings, fromPath);
if (actions?.enabled === false || actions?.enabled === true) {
addDeprecation({
message: `"xpack.actions.enabled" is deprecated. The ability to disable this plugin will be removed in 8.0.0.`,
correctiveActions: {
Expand Down
42 changes: 42 additions & 0 deletions x-pack/plugins/alerting/server/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { config } from './index';
import { applyDeprecations, configDeprecationFactory } from '@kbn/config';

const CONFIG_PATH = 'xpack.alerting';
const applyStackAlertDeprecations = (settings: Record<string, unknown> = {}) => {
const deprecations = config.deprecations!(configDeprecationFactory);
const deprecationMessages: string[] = [];
const _config = {
[CONFIG_PATH]: settings,
};
const { config: migrated } = applyDeprecations(
_config,
deprecations.map((deprecation) => ({
deprecation,
path: CONFIG_PATH,
})),
() => ({ message }) => deprecationMessages.push(message)
);
return {
messages: deprecationMessages,
migrated,
};
};

describe('index', () => {
describe('deprecations', () => {
it('should deprecate .enabled flag', () => {
const { messages } = applyStackAlertDeprecations({ enabled: false });
expect(messages).toMatchInlineSnapshot(`
Array [
"\\"xpack.alerting.enabled\\" is deprecated. The ability to disable this plugin will be removed in 8.0.0.",
]
`);
});
});
});
8 changes: 3 additions & 5 deletions x-pack/plugins/alerting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { get } from 'lodash';
import type { PublicMethodsOf } from '@kbn/utility-types';
import { RulesClient as RulesClientClass } from './rules_client';
import { PluginConfigDescriptor, PluginInitializerContext } from '../../../../src/core/server';
Expand Down Expand Up @@ -59,10 +59,8 @@ export const config: PluginConfigDescriptor<AlertsConfigType> = {
'xpack.alerting.invalidateApiKeysTask.removalDelay'
),
(settings, fromPath, addDeprecation) => {
if (
settings?.xpack?.alerting?.enabled === false ||
settings?.xpack?.alerting?.enabled === true
) {
const alerting = get(settings, fromPath);
if (alerting?.enabled === false || alerting?.enabled === true) {
addDeprecation({
message: `"xpack.alerting.enabled" is deprecated. The ability to disable this plugin will be removed in 8.0.0.`,
correctiveActions: {
Expand Down
42 changes: 42 additions & 0 deletions x-pack/plugins/stack_alerts/server/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { config } from './index';
import { applyDeprecations, configDeprecationFactory } from '@kbn/config';

const CONFIG_PATH = 'xpack.stack_alerts';
const applyStackAlertDeprecations = (settings: Record<string, unknown> = {}) => {
const deprecations = config.deprecations!(configDeprecationFactory);
const deprecationMessages: string[] = [];
const _config = {
[CONFIG_PATH]: settings,
};
const { config: migrated } = applyDeprecations(
_config,
deprecations.map((deprecation) => ({
deprecation,
path: CONFIG_PATH,
})),
() => ({ message }) => deprecationMessages.push(message)
);
return {
messages: deprecationMessages,
migrated,
};
};

describe('index', () => {
describe('deprecations', () => {
it('should deprecate .enabled flag', () => {
const { messages } = applyStackAlertDeprecations({ enabled: false });
expect(messages).toMatchInlineSnapshot(`
Array [
"\\"xpack.stack_alerts.enabled\\" is deprecated. The ability to disable this plugin will be removed in 8.0.0.",
]
`);
});
});
});
8 changes: 3 additions & 5 deletions x-pack/plugins/stack_alerts/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { get } from 'lodash';
import { PluginConfigDescriptor, PluginInitializerContext } from 'src/core/server';
import { AlertingBuiltinsPlugin } from './plugin';
import { configSchema, Config } from '../common/config';
Expand All @@ -15,10 +15,8 @@ export const config: PluginConfigDescriptor<Config> = {
schema: configSchema,
deprecations: () => [
(settings, fromPath, addDeprecation) => {
if (
settings?.xpack?.stack_alerts?.enabled === false ||
settings?.xpack?.stack_alerts?.enabled === true
) {
const stackAlerts = get(settings, fromPath);
if (stackAlerts?.enabled === false || stackAlerts?.enabled === true) {
addDeprecation({
message: `"xpack.stack_alerts.enabled" is deprecated. The ability to disable this plugin will be removed in 8.0.0.`,
correctiveActions: {
Expand Down

0 comments on commit 87cf604

Please sign in to comment.