Skip to content

Commit

Permalink
move code shared with alerting api-integration plugins into a package (
Browse files Browse the repository at this point in the history
…#148846)

We're working on converting all plugins into packages, which turns
almost all code in the repository into a package except for things like
the `test` and `x-pack/test` directories. The problem we ran into is
that the alerting api-integration test plugins are being migrated to
packages but they are currently consuming a handful of helpers from the
parent `../lib` directory. This doesn't work, as packages can only
import other packages and the `../lib` directory isn't in a package,
it's just free-floating `x-pack/test` code. To fix this I've moved the
necessary components out of `common/lib` and into `packages/helpers`
which is importable via `@kbn/alerting-api-integration-helpers` and
updated all the uses to access this new package.
  • Loading branch information
Spencer committed Jan 12, 2023
1 parent 4da8f56 commit 1880e8b
Show file tree
Hide file tree
Showing 59 changed files with 139 additions and 147 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1086,3 +1086,4 @@ x-pack/packages/ml/nested_property @elastic/ml-ui
x-pack/packages/ml/query_utils @elastic/ml-ui
x-pack/packages/ml/string_hash @elastic/ml-ui
x-pack/packages/ml/url_state @elastic/ml-ui
x-pack/test/alerting_api_integration/packages/helpers @elastic/response-ops
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@
"@jest/reporters": "^29.3.1",
"@jest/transform": "^29.3.1",
"@jest/types": "^29.3.1",
"@kbn/alerting-api-integration-helpers": "link:x-pack/test/alerting_api_integration/packages/helpers",
"@kbn/ambient-common-types": "link:packages/kbn-ambient-common-types",
"@kbn/ambient-ftr-types": "link:packages/kbn-ambient-ftr-types",
"@kbn/ambient-storybook-types": "link:packages/kbn-ambient-storybook-types",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@kbn/aiops-plugin/*": ["x-pack/plugins/aiops/*"],
"@kbn/aiops-utils": ["x-pack/packages/ml/aiops_utils"],
"@kbn/aiops-utils/*": ["x-pack/packages/ml/aiops_utils/*"],
"@kbn/alerting-api-integration-helpers": ["x-pack/test/alerting_api_integration/packages/helpers"],
"@kbn/alerting-api-integration-helpers/*": ["x-pack/test/alerting_api_integration/packages/helpers/*"],
"@kbn/alerting-example-plugin": ["x-pack/examples/alerting_example"],
"@kbn/alerting-example-plugin/*": ["x-pack/examples/alerting_example/*"],
"@kbn/alerting-fixture-plugin": ["x-pack/test/functional_with_es_ssl/plugins/alerts"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import { ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { Space, User } from '../types';
import { ObjectRemover } from './object_remover';
import { getUrlPrefix } from './space_test_utils';
import { ES_TEST_INDEX_NAME } from './es_test_index_tool';
import { getTestRuleData } from './get_test_rule_data';

export interface AlertUtilsOpts {
Expand Down
1 change: 0 additions & 1 deletion x-pack/test/alerting_api_integration/common/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

export { ObjectRemover } from './object_remover';
export { getUrlPrefix } from './space_test_utils';
export { ES_TEST_INDEX_NAME, ESTestIndexTool } from './es_test_index_tool';
export { getTestRuleData } from './get_test_rule_data';
export {
AlertUtils,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import getPort from 'get-port';
import http from 'http';
import httpProxy from 'http-proxy';
import { getProxyPort } from '../../../lib/get_proxy_server';
import { getProxyPort } from '@kbn/alerting-api-integration-helpers';
import { getDataFromRequest } from './data_handler';

export interface ProxyArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
RuleTypeParams,
} from '@kbn/alerting-plugin/server';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { FixtureStartDeps, FixtureSetupDeps } from './plugin';
import { ES_TEST_INDEX_NAME } from '../../../lib';

export const EscapableStrings = {
escapableBold: '*bold*',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/alerting-api-integration-helpers

A package to hold alerting api-integration test helpers that are shared with the the alerting api-integration plugins.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/
import type { Client } from '@elastic/elasticsearch';

export const ES_TEST_INDEX_NAME = '.kibana-alerting-test-data';

export class ESTestIndexTool {
Expand Down
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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './es_test_index_tool';
export * from './get_proxy_server';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../../..',
roots: ['<rootDir>/x-pack/test/alerting_api_integration/packages/helpers'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "test-helper",
"id": "@kbn/alerting-api-integration-helpers",
"owner": "@elastic/response-ops",
"devOnly": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/alerting-api-integration-helpers",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import httpProxy from 'http-proxy';
import expect from '@kbn/expect';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import httpProxy from 'http-proxy';
import expect from '@kbn/expect';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import expect from '@kbn/expect';
import { promisify } from 'util';
import httpProxy from 'http-proxy';
import { KBN_KEY_PATH } from '@kbn/dev-utils';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import {
ExternalServiceSimulator,
getExternalServiceSimulatorPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import httpProxy from 'http-proxy';
import expect from '@kbn/expect';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import httpProxy from 'http-proxy';
import expect from '@kbn/expect';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { asyncForEach } from '@kbn/std';
import getPort from 'get-port';
import http from 'http';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { getServiceNowServer } from '../../../../../common/plugins/actions_simulators/server/plugin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { asyncForEach } from '@kbn/std';
import getPort from 'get-port';
import http from 'http';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { getServiceNowServer } from '../../../../../common/plugins/actions_simulators/server/plugin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { asyncForEach } from '@kbn/std';
import getPort from 'get-port';
import http from 'http';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { getServiceNowServer } from '../../../../../common/plugins/actions_simulators/server/plugin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import httpProxy from 'http-proxy';
import expect from '@kbn/expect';
import http from 'http';
import getPort from 'get-port';
import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import { getSlackServer } from '../../../../../common/plugins/actions_simulators/server/plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import expect from '@kbn/expect';
import getPort from 'get-port';
import http from 'http';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { getSwimlaneServer } from '../../../../../common/plugins/actions_simulators/server/plugin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import http from 'http';
import expect from '@kbn/expect';
import { URL, format as formatUrl } from 'url';
import getPort from 'get-port';
import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import httpProxy from 'http-proxy';
import expect from '@kbn/expect';

import { getHttpProxyServer } from '../../../../../common/lib/get_proxy_server';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

import expect from '@kbn/expect';
import { IValidatedEvent, nanosToMillis } from '@kbn/event-log-plugin/server';
import { ESTestIndexTool, ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { UserAtSpaceScenarios } from '../../../scenarios';
import {
ESTestIndexTool,
ES_TEST_INDEX_NAME,
getUrlPrefix,
ObjectRemover,
getEventLog,
} from '../../../../common/lib';
import { getUrlPrefix, ObjectRemover, getEventLog } from '../../../../common/lib';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { IValidatedEvent, nanosToMillis } from '@kbn/event-log-plugin/server';
import { TaskRunning, TaskRunningStage } from '@kbn/task-manager-plugin/server/task_running';
import { ConcreteTaskInstance } from '@kbn/task-manager-plugin/server';
import { ESTestIndexTool, ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { UserAtSpaceScenarios, Superuser } from '../../../scenarios';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
ESTestIndexTool,
ES_TEST_INDEX_NAME,
getUrlPrefix,
getTestRuleData,
ObjectRemover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

import expect from '@kbn/expect';
import { ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { UserAtSpaceScenarios } from '../../../scenarios';
import {
getTestRuleData,
getUrlPrefix,
ObjectRemover,
getEventLog,
AlertUtils,
ES_TEST_INDEX_NAME,
} from '../../../../common/lib';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

import expect from '@kbn/expect';

import { ESTestIndexTool } from '@kbn/alerting-api-integration-helpers';
import { Spaces } from '../../../scenarios';
import {
getUrlPrefix,
ObjectRemover,
getTestRuleData,
getEventLog,
ESTestIndexTool,
} from '../../../../common/lib';
import { getUrlPrefix, ObjectRemover, getTestRuleData, getEventLog } from '../../../../common/lib';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
*/

import expect from '@kbn/expect';
import { ESTestIndexTool, ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { UserAtSpaceScenarios } from '../../../scenarios';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getUrlPrefix,
getTestRuleData,
ObjectRemover,
AlertUtils,
ESTestIndexTool,
ES_TEST_INDEX_NAME,
} from '../../../../common/lib';
import { getUrlPrefix, getTestRuleData, ObjectRemover, AlertUtils } from '../../../../common/lib';

// eslint-disable-next-line import/no-default-export
export default function createFindTests({ getService }: FtrProviderContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import axios from 'axios';
import httpProxy from 'http-proxy';

import expect from '@kbn/expect';
import { getHttpProxyServer } from '@kbn/alerting-api-integration-helpers';
import { Spaces } from '../../../scenarios';
import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import { getSlackServer } from '../../../../common/plugins/actions_simulators/server/plugin';
import { getHttpProxyServer } from '../../../../common/lib/get_proxy_server';

// eslint-disable-next-line import/no-default-export
export default function executionStatusAlertTests({ getService }: FtrProviderContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import expect from '@kbn/expect';
import { SavedObjectsUtils } from '@kbn/core/server';
import { ESTestIndexTool } from '@kbn/alerting-api-integration-helpers';
import { UserAtSpaceScenarios, Superuser } from '../../../scenarios';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import { ESTestIndexTool, getUrlPrefix, ObjectRemover, AlertUtils } from '../../../../common/lib';
import { getUrlPrefix, ObjectRemover, AlertUtils } from '../../../../common/lib';
import { setupSpacesAndUsers } from '../../../setup';

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
*/

import expect from '@kbn/expect';
import { ESTestIndexTool } from '@kbn/alerting-api-integration-helpers';
import { Spaces, Superuser } from '../../../scenarios';
import {
getUrlPrefix,
getEventLog,
getTestRuleData,
ESTestIndexTool,
TaskManagerDoc,
} from '../../../../common/lib';
import { getUrlPrefix, getEventLog, getTestRuleData, TaskManagerDoc } from '../../../../common/lib';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { Space, User } from '../common/types';
import { ES_TEST_INDEX_NAME } from '../common/lib';

const NoKibanaPrivileges: User = {
username: 'no_kibana_privileges',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

import expect from '@kbn/expect';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { ESTestIndexTool, ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers';
import { Spaces } from '../../scenarios';
import {
ESTestIndexTool,
ES_TEST_INDEX_NAME,
getUrlPrefix,
ObjectRemover,
} from '../../../common/lib';
import { getUrlPrefix, ObjectRemover } from '../../../common/lib';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
Expand Down
Loading

0 comments on commit 1880e8b

Please sign in to comment.