Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FTR] Refactor test/common/services/* -> packages/kbn-ftr-common-functional-[ui-]services/* #191805

Merged
merged 29 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2a8e956
[FTR] Refactor test/common/services
wayneseymour Aug 19, 2024
6c60b52
satisfy "node scripts/build_api_docs --plugin @kbn/ftr-common-functio…
wayneseymour Aug 22, 2024
a6fd2e7
fixup threat intel svcs
wayneseymour Aug 22, 2024
07b6d70
drop the junit:merge to see if this lessens the total ci time, such t…
wayneseymour Aug 23, 2024
f203a90
fixup yet another pointer for common svcs
wayneseymour Aug 23, 2024
cea8f31
try to drop cypress tests for now
wayneseymour Aug 23, 2024
589cb63
put this back
wayneseymour Aug 23, 2024
899a3a9
drop these, just like I dropped defend_workflows script
wayneseymour Aug 23, 2024
1f33165
Turn defend_workflows.sh and defend_workflows.sh back on in ci
wayneseymour Aug 26, 2024
499e40a
Fix up from Dima's comment;
wayneseymour Aug 26, 2024
ddd95b2
attempt to extend the timeout's of the two scripts that are being can…
wayneseymour Aug 26, 2024
ca91369
put these back as it made no difference
wayneseymour Aug 26, 2024
76cc713
[pairing with tom] drop svcs for now
wayneseymour Aug 27, 2024
990537b
[pairing with tom] add test/common/services back, but using the new '…
wayneseymour Aug 27, 2024
4e4d0b2
[pairing with tom] repoint to *
wayneseymour Aug 27, 2024
0298459
Add services stanza with both common svcs spread into it
wayneseymour Aug 30, 2024
1b8a900
commit the first handfull. Committing due to it being obvious the se…
wayneseymour Aug 30, 2024
082d7d0
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Aug 30, 2024
0f53a16
Change svc refs.
wayneseymour Aug 30, 2024
5860bf4
Add comments to hopefully trigger any other "extra" tests.
wayneseymour Aug 30, 2024
f112035
Merge branch 'main' of github.com:elastic/kibana into refactor-common…
wayneseymour Sep 2, 2024
6f4aad4
Merge branch 'main' of github.com:elastic/kibana into refactor-common…
wayneseymour Sep 2, 2024
357724e
fix svc refs.
wayneseymour Sep 2, 2024
18a38c5
Merge branch 'main' of github.com:elastic/kibana into refactor-common…
wayneseymour Sep 2, 2024
0c26add
Drop these.
wayneseymour Sep 2, 2024
e6dc4f7
Merge branch 'main' of github.com:elastic/kibana into refactor-common…
wayneseymour Sep 2, 2024
0aa9c29
Merge branch 'main' into refactor-common-svcs
elasticmachine Sep 3, 2024
4f16b5b
Merge branch 'main' into refactor-common-svcs
elasticmachine Sep 3, 2024
e89522d
Merge branch 'main' of github.com:elastic/kibana into refactor-common…
wayneseymour Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Tests should run at the positive security boundary condition, meaning that they

The functional UI tests now default to logging in with a user named `test_user` and the roles of this user can be changed dynamically without logging in and out.

In order to achieve this a new service was introduced called `createTestUserService` (see `test/common/services/security/test_user.ts`). The purpose of this test user service is to create roles defined in the test config files and setRoles() or restoreDefaults().
In order to achieve this a new service was introduced called `createTestUserService` (see `packages/kbn-ftr-common-functional-ui-services/services/security/test_user.ts`). The purpose of this test user service is to create roles defined in the test config files and setRoles() or restoreDefaults().

An example of how to set the role like how its defined below:

Expand Down Expand Up @@ -366,22 +366,22 @@ await testSubjects.click(‘containerButton’);
** `find.allByCssSelector()`

**retry:**:::
// * Source: {kibana-blob}test/common/services/retry/retry.ts[test/common/services/retry/retry.ts]
// * Source: {kibana-blob}packages/kbn-ftr-common-functional-services/services/retry/retry.ts[packages/kbn-ftr-common-functional-services/services/retry/retry.ts]
* Helpers for retrying operations
* Popular methods:
** `retry.try(fn, onFailureBlock)` - Execute `fn` in a loop until it succeeds or the default timeout elapses. The optional `onFailureBlock` is executed before each retry attempt.
** `retry.tryForTime(ms, fn, onFailureBlock)` - Execute `fn` in a loop until it succeeds or `ms` milliseconds elapses. The optional `onFailureBlock` is executed before each retry attempt.

**kibanaServer:**:::
// * Source: {kibana-blob}test/common/services/kibana_server/kibana_server.js[test/common/services/kibana_server/kibana_server.js]
// * Source: {kibana-blob}packages/kbn-ftr-common-functional-services/services/kibana_server/kibana_server.ts[packages/kbn-ftr-common-functional-services/services/kibana_server/kibana_server.ts]
* Helpers for interacting with {kib}'s server
* Commonly used methods:
** `kibanaServer.uiSettings.update()`
** `kibanaServer.version.get()`
** `kibanaServer.status.getOverallState()`

**esArchiver:**:::
// * Source: {kibana-blob}test/common/services/es_archiver.ts[test/common/services/es_archiver.ts]
// * Source: {kibana-blob}packages/kbn-ftr-common-functional-services/services/es_archiver.ts[packages/kbn-ftr-common-functional-services/services/es_archiver.ts]
* Load/unload archives created with the `esArchiver`
* Popular methods:
** `esArchiver.load(path)`
Expand All @@ -393,7 +393,7 @@ Full list of services that are used in functional tests can be found here: {kiba

**Low-level utilities:**:::
* es
// ** Source: {kibana-blob}test/common/services/es.ts[test/common/services/es.ts]
// ** Source: {kibana-blob}packages/kbn-ftr-common-functional-services/services/es.ts[packages/kbn-ftr-common-functional-services/services/es.ts]
** {es} client
** Higher level options: `kibanaServer.uiSettings` or `esArchiver`
* remote
Expand Down
9 changes: 9 additions & 0 deletions packages/kbn-ftr-common-functional-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ProvidedType } from '@kbn/test';
export { services as commonFunctionalServices } from './services/all';

import { KibanaServerProvider } from './services/kibana_server';
export { KibanaServerProvider } from './services/kibana_server';
export type KibanaServer = ProvidedType<typeof KibanaServerProvider>;

export { RetryService } from './services/retry';
Expand All @@ -18,6 +19,7 @@ import { EsArchiverProvider } from './services/es_archiver';
export type EsArchiver = ProvidedType<typeof EsArchiverProvider>;

import { EsProvider } from './services/es';
export { EsProvider } from './services/es';
export type Es = ProvidedType<typeof EsProvider>;

import { SupertestWithoutAuthProvider } from './services/supertest_without_auth';
Expand All @@ -29,3 +31,10 @@ import { SamlAuthProvider } from './services/saml_auth/saml_auth_provider';
export type SamlAuthProviderType = ProvidedType<typeof SamlAuthProvider>;

export type { FtrProviderContext } from './services/ftr_provider_context';
export { runSavedObjInfoSvc } from './services/saved_object_info';

export type { BsearchService, SendOptions } from './services/bsearch';
export { SavedObjectInfoService } from './services/saved_object_info';
export { DeploymentService } from './services/deployment';
export { IndexPatternsService } from './services/index_patterns';
export { RandomnessService } from './services/randomness';
14 changes: 14 additions & 0 deletions packages/kbn-ftr-common-functional-services/services/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { EsArchiverProvider } from './es_archiver';
import { EsProvider } from './es';
import { KibanaServerProvider } from './kibana_server';
import { RetryService } from './retry';
import { BsearchService } from './bsearch';
import { ConsoleProvider } from './console';
import { DeploymentService } from './deployment';
import { EsDeleteAllIndicesProvider } from './es_delete_all_indices';
import { IndexPatternsService } from './index_patterns';
import { SavedObjectInfoService } from './saved_object_info';
import { RandomnessService } from './randomness';
import { SupertestWithoutAuthProvider } from './supertest_without_auth';
import { SamlAuthProvider } from './saml_auth';

Expand All @@ -18,6 +25,13 @@ export const services = {
kibanaServer: KibanaServerProvider,
esArchiver: EsArchiverProvider,
retry: RetryService,
bsearch: BsearchService,
console: ConsoleProvider,
deployment: DeploymentService,
esDeleteAllIndices: EsDeleteAllIndicesProvider,
indexPatterns: IndexPatternsService,
savedObjectInfo: SavedObjectInfoService,
randomness: RandomnessService,
supertestWithoutAuth: SupertestWithoutAuthProvider,
samlAuth: SamlAuthProvider,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type SuperTest from 'supertest';
import type { IEsSearchResponse } from '@kbn/search-types';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { BFETCH_ROUTE_VERSION_LATEST } from '@kbn/bfetch-plugin/common';
import { FtrService } from '../ftr_provider_context';
import { FtrService } from './ftr_provider_context';

/**
* Function copied from here:
Expand Down Expand Up @@ -62,6 +62,7 @@ export interface SendOptions {
* });
* expect(response).eql({ ... your value ... });
*/

export class BsearchService extends FtrService {
private readonly retry = this.ctx.getService('retry');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Side Public License, v 1.
*/

import type { FtrProviderContext } from '../../ftr_provider_context';
import type { FtrProviderContext } from './ftr_provider_context';

export function helpers(getService: FtrProviderContext['getService']) {
export function ConsoleProvider({ getService }: FtrProviderContext) {
const client = getService('es');

const createIndex = async (indexName: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Agent } from 'https';
import fetch from 'node-fetch';
import { getUrl } from '@kbn/test';

import { FtrService } from '../ftr_provider_context';
import { FtrService } from './ftr_provider_context';

export class DeploymentService extends FtrService {
private readonly config = this.ctx.getService('config');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { FtrProviderContext } from '../ftr_provider_context';
import { FtrProviderContext } from './ftr_provider_context';

export function EsDeleteAllIndicesProvider({ getService }: FtrProviderContext) {
const log = getService('log');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
* Side Public License, v 1.
*/

import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import type { DataViewSpec } from '@kbn/data-plugin/common';

import { INITIAL_REST_VERSION } from '@kbn/data-views-plugin/server/constants';
import { DataViewSpec } from '@kbn/data-plugin/common';
import { FtrService } from '../ftr_provider_context';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { FtrService } from './ftr_provider_context';

export class IndexPatternsService extends FtrService {
private readonly kibanaServer = this.ctx.getService('kibanaServer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Chance from 'chance';
import { ToolingLog } from '@kbn/tooling-log';

import { FtrService } from '../ftr_provider_context';
import { FtrService } from './ftr_provider_context';

let __CACHED_SEED__: number | undefined;
function getSeed(log: ToolingLog) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { flow, pipe } from 'fp-ts/function';
import * as TE from 'fp-ts/lib/TaskEither';
import * as T from 'fp-ts/lib/Task';
import { ToolingLog } from '@kbn/tooling-log';
import { FtrService } from '../../ftr_provider_context';
import { FtrService } from '../ftr_provider_context';
import { print } from './utils';

const pluck =
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-ftr-common-functional-services/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
"@kbn/es-archiver",
"@kbn/test",
"@kbn/expect",
"@kbn/search-types",
"@kbn/core-http-common",
"@kbn/bfetch-plugin",
"@kbn/data-plugin",
"@kbn/dev-cli-runner",
"@kbn/dev-cli-errors",
"@kbn/repo-info",
"@kbn/es",
"@kbn/data-views-plugin"
],
"exclude": [
"target/**/*",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ftr-common-functional-ui-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export {
} from './services/remote/network_profiles';
export type { TimeoutOpt } from './types';
export { TestSubjects } from './services/test_subjects';
export { SecurityService } from './services/security';
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FindProvider } from './find';
import { TestSubjects } from './test_subjects';
import { BrowserProvider } from './browser';
import { ToastsService } from './toasts';
import { SecurityServiceProvider } from './security';

export const services = {
retryOnStale: RetryOnStaleProvider,
Expand All @@ -20,4 +21,5 @@ export const services = {
testSubjects: TestSubjects,
browser: BrowserProvider,
toasts: ToastsService,
security: SecurityServiceProvider,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
*/

import { GenericFtrProviderContext, GenericFtrService } from '@kbn/test';
import { RetryService } from '@kbn/ftr-common-functional-services';
import {
RetryService,
EsProvider,
KibanaServerProvider,
} from '@kbn/ftr-common-functional-services';
import { services as commonFunctionalUiServices } from './all';

const services = {
...commonFunctionalUiServices,
retry: RetryService,
es: EsProvider,
kibanaServer: KibanaServerProvider,
};

export type FtrProviderContext = GenericFtrProviderContext<typeof services, {}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export { SecurityServiceProvider } from './security';
export { SecurityService, SecurityServiceProvider } from './security';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Role } from './role';
import { User } from './user';
import { RoleMappings } from './role_mappings';
import { FtrProviderContext } from '../../ftr_provider_context';
import { FtrProviderContext } from '../ftr_provider_context';
import { createTestUserService, TestUserSupertestProvider, TestUser } from './test_user';
import { createSystemIndicesUser } from './system_indices_user';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createEsClientForFtrConfig,
createRemoteEsClientForFtrConfig,
} from '@kbn/test';
import { FtrProviderContext } from '../../ftr_provider_context';
import { FtrProviderContext } from '../ftr_provider_context';

const SYSTEM_INDICES_SUPERUSER_ROLE = 'system_indices_superuser';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import { format as formatUrl } from 'url';
import supertest from 'supertest';

import { type Browser, TestSubjects } from '@kbn/ftr-common-functional-ui-services';
import type { Browser } from '../browser';
import type { TestSubjects } from '../test_subjects';
import { Role } from './role';
import { User } from './user';
import { FtrService, FtrProviderContext } from '../../ftr_provider_context';
import { FtrService, FtrProviderContext } from '../ftr_provider_context';

const TEST_USER_NAME = 'test_user';
const TEST_USER_PASSWORD = 'changeme';
Expand Down
2 changes: 1 addition & 1 deletion scripts/saved_objs_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
*/

require('../src/setup_node_env');
require('@kbn/test-suites-src/common/services/saved_object_info').runSavedObjInfoSvc();
require('@kbn/ftr-common-functional-services').runSavedObjInfoSvc();
7 changes: 5 additions & 2 deletions test/analytics/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
*/

import { GenericFtrProviderContext } from '@kbn/test';
import { services as commonServices } from '../../common/services';
import { commonFunctionalServices } from '@kbn/ftr-common-functional-services';
import { commonFunctionalUIServices } from '@kbn/ftr-common-functional-ui-services';

import { services as functionalServices } from '../../functional/services';
import { pageObjects } from '../../functional/page_objects';

import { KibanaEBTServerProvider, KibanaEBTUIProvider } from './kibana_ebt';

export const services = {
...commonServices,
...commonFunctionalServices,
...commonFunctionalUIServices,
...functionalServices,
kibana_ebt_server: KibanaEBTServerProvider,
kibana_ebt_ui: KibanaEBTUIProvider,
Expand Down
46 changes: 18 additions & 28 deletions test/api_integration/apis/console/autocomplete_entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,11 @@

import expect from '@kbn/expect';
import type { FtrProviderContext } from '../../ftr_provider_context';
import { helpers } from './helpers';

export default ({ getService }: FtrProviderContext) => {
const {
createIndex,
createAlias,
createLegacyTemplate,
createIndexTemplate,
createComponentTemplate,
createDataStream,
deleteIndex,
deleteAlias,
deleteLegacyTemplate,
deleteIndexTemplate,
deleteComponentTemplate,
deleteDataStream,
} = helpers(getService);

const console = getService('console');
const supertest = getService('supertest');

const sendRequest = (query: object) =>
supertest.get('/api/console/autocomplete_entities').query(query);

Expand All @@ -40,22 +26,26 @@ export default ({ getService }: FtrProviderContext) => {

before(async () => {
// Setup indices, aliases, templates, and data streams
await createIndex(indexName);
await createAlias(indexName, aliasName);
await createComponentTemplate(componentTemplateName);
await createIndexTemplate(indexTemplateName, [dataStreamName], [componentTemplateName]);
await createDataStream(dataStreamName);
await createLegacyTemplate(legacyTemplateName);
await console.createIndex(indexName);
await console.createAlias(indexName, aliasName);
await console.createComponentTemplate(componentTemplateName);
await console.createIndexTemplate(
indexTemplateName,
[dataStreamName],
[componentTemplateName]
);
await console.createDataStream(dataStreamName);
await console.createLegacyTemplate(legacyTemplateName);
});

after(async () => {
// Cleanup indices, aliases, templates, and data streams
await deleteAlias(indexName, aliasName);
await deleteIndex(indexName);
await deleteDataStream(dataStreamName);
await deleteIndexTemplate(indexTemplateName);
await deleteComponentTemplate(componentTemplateName);
await deleteLegacyTemplate(legacyTemplateName);
await console.deleteAlias(indexName, aliasName);
await console.deleteIndex(indexName);
await console.deleteDataStream(dataStreamName);
await console.deleteIndexTemplate(indexTemplateName);
await console.deleteComponentTemplate(componentTemplateName);
await console.deleteLegacyTemplate(legacyTemplateName);
});

it('should not succeed if no settings are provided in query params', async () => {
Expand Down
7 changes: 4 additions & 3 deletions test/api_integration/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
* Side Public License, v 1.
*/

import { services as commonServices } from '../../common/services';

import { commonFunctionalServices } from '@kbn/ftr-common-functional-services';
import { commonFunctionalUIServices } from '@kbn/ftr-common-functional-ui-services';
import { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './supertest';

export const services = {
...commonServices,
...commonFunctionalServices,
...commonFunctionalUIServices,
supertest: KibanaSupertestProvider,
esSupertest: ElasticsearchSupertestProvider,
};
2 changes: 0 additions & 2 deletions test/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import path from 'path';
import { format as formatUrl } from 'url';
import { esTestConfig, kbnTestConfig, kibanaServerTestUser } from '@kbn/test';
import { services } from './services';

export default function () {
const servers = {
Expand Down Expand Up @@ -85,6 +84,5 @@ export default function () {
})}`,
],
},
services,
};
}
Loading
Loading