Skip to content

Commit

Permalink
migrated fixture in alerting functional test to NP
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Mar 10, 2020
1 parent 9024c40 commit d5c4293
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "alerting_fixture",
"version": "1.0.0",
"kibanaVersion": "kibana",
"configPath": ["xpack"],
"requiredPlugins": ["alerting"],
"server": true,
"ui": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertingFixturePlugin } from './plugin';

export const plugin = () => new AlertingFixturePlugin();
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Plugin, CoreSetup } from 'kibana/public';
import { PluginSetupContract as AlertingSetup } from '../../../../../../plugins/alerting/public';
import { AlertType, SanitizedAlert } from '../../../../../../plugins/alerting/common';

export type Setup = void;
export type Start = void;

export interface AlertingExamplePublicSetupDeps {
alerting: AlertingSetup;
}

export class AlertingFixturePlugin implements Plugin<Setup, Start, AlertingExamplePublicSetupDeps> {
public setup(core: CoreSetup, { alerting }: AlertingExamplePublicSetupDeps) {
alerting.registerNavigation(
'test.noop',
'consumer.noop',
(alert: SanitizedAlert, alertType: AlertType) => ({
state: {
// LOLs
alert: JSON.parse(JSON.stringify(alert)),
alertType: JSON.parse(JSON.stringify(alertType)),
},
})
);
}

public start() {}
public stop() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializer } from 'kibana/server';
import { AlertingFixturePlugin } from './plugin';

export const plugin: PluginInitializer<void, void> = () => new AlertingFixturePlugin();
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,39 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertType } from '../../../../../plugins/alerting/server';

// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
require: ['alerting'],
name: 'alerts',
init(server: any) {
createNoopAlertType(server.newPlatform.setup.plugins.alerting);
createAlwaysFiringAlertType(server.newPlatform.setup.plugins.alerting);
},
});
import { Plugin, CoreSetup } from 'kibana/server';
import {
PluginSetupContract as AlertingSetup,
AlertType,
} from '../../../../../../plugins/alerting/server';

// this plugin's dependendencies
export interface AlertingExampleDeps {
alerting: AlertingSetup;
}

export class AlertingFixturePlugin implements Plugin<void, void, AlertingExampleDeps> {
public setup(core: CoreSetup, { alerting }: AlertingExampleDeps) {
createNoopAlertType(alerting);
createAlwaysFiringAlertType(alerting);
}

public start() {}
public stop() {}
}

function createNoopAlertType(setupContract: any) {
function createNoopAlertType(alerting: AlertingSetup) {
const noopAlertType: AlertType = {
id: 'test.noop',
name: 'Test: Noop',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
async executor() {},
};
setupContract.registerType(noopAlertType);
alerting.registerType(noopAlertType);
}

function createAlwaysFiringAlertType(setupContract: any) {
function createAlwaysFiringAlertType(alerting: AlertingSetup) {
// Alert types
const alwaysFiringAlertType: any = {
id: 'test.always-firing',
Expand All @@ -54,5 +61,5 @@ function createAlwaysFiringAlertType(setupContract: any) {
};
},
};
setupContract.registerType(alwaysFiringAlertType);
alerting.registerType(alwaysFiringAlertType);
}

0 comments on commit d5c4293

Please sign in to comment.