Skip to content

Commit

Permalink
Revert "[FTR] Refactor test/common/services/* -> packages/kbn-ftr-com…
Browse files Browse the repository at this point in the history
…mon-functional-[ui-]services/* (elastic#189051)"

This reverts commit 09a3658.
  • Loading branch information
jbudz committed Aug 29, 2024
1 parent 1016ef0 commit 0894c8b
Show file tree
Hide file tree
Showing 70 changed files with 185 additions and 214 deletions.
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 `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().
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().

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

**esArchiver:**:::
// * Source: {kibana-blob}packages/kbn-ftr-common-functional-services/services/es_archiver.ts[packages/kbn-ftr-common-functional-services/services/es_archiver.ts]
// * Source: {kibana-blob}test/common/services/es_archiver.ts[test/common/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}packages/kbn-ftr-common-functional-services/services/es.ts[packages/kbn-ftr-common-functional-services/services/es.ts]
// ** Source: {kibana-blob}test/common/services/es.ts[test/common/services/es.ts]
** {es} client
** Higher level options: `kibanaServer.uiSettings` or `esArchiver`
* remote
Expand Down
9 changes: 0 additions & 9 deletions packages/kbn-ftr-common-functional-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 @@ -19,7 +18,6 @@ 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 @@ -31,10 +29,3 @@ 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: 0 additions & 14 deletions packages/kbn-ftr-common-functional-services/services/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ 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 @@ -25,13 +18,6 @@ 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,
};
7 changes: 0 additions & 7 deletions packages/kbn-ftr-common-functional-services/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@
"@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: 0 additions & 1 deletion packages/kbn-ftr-common-functional-ui-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ 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,7 +12,6 @@ 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 @@ -21,5 +20,4 @@ export const services = {
testSubjects: TestSubjects,
browser: BrowserProvider,
toasts: ToastsService,
security: SecurityServiceProvider,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@
*/

import { GenericFtrProviderContext, GenericFtrService } from '@kbn/test';
import {
RetryService,
EsProvider,
KibanaServerProvider,
} from '@kbn/ftr-common-functional-services';
import { RetryService } 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
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/ftr-common-functional-services').runSavedObjInfoSvc();
require('@kbn/test-suites-src/common/services/saved_object_info').runSavedObjInfoSvc();
7 changes: 2 additions & 5 deletions test/analytics/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
*/

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

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

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

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

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

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

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

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

before(async () => {
// Setup indices, aliases, templates, and data streams
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);
await createIndex(indexName);
await createAlias(indexName, aliasName);
await createComponentTemplate(componentTemplateName);
await createIndexTemplate(indexTemplateName, [dataStreamName], [componentTemplateName]);
await createDataStream(dataStreamName);
await createLegacyTemplate(legacyTemplateName);
});

after(async () => {
// Cleanup indices, aliases, templates, and data streams
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);
await deleteAlias(indexName, aliasName);
await deleteIndex(indexName);
await deleteDataStream(dataStreamName);
await deleteIndexTemplate(indexTemplateName);
await deleteComponentTemplate(componentTemplateName);
await deleteLegacyTemplate(legacyTemplateName);
});

it('should not succeed if no settings are provided in query params', async () => {
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 ConsoleProvider({ getService }: FtrProviderContext) {
export function helpers(getService: FtrProviderContext['getService']) {
const client = getService('es');

const createIndex = async (indexName: string) => {
Expand Down
7 changes: 3 additions & 4 deletions test/api_integration/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* Side Public License, v 1.
*/

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

import { KibanaSupertestProvider, ElasticsearchSupertestProvider } from './supertest';

export const services = {
...commonFunctionalServices,
...commonFunctionalUIServices,
...commonServices,
supertest: KibanaSupertestProvider,
esSupertest: ElasticsearchSupertestProvider,
};
2 changes: 2 additions & 0 deletions test/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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 @@ -84,5 +85,6 @@ export default function () {
})}`,
],
},
services,
};
}
14 changes: 14 additions & 0 deletions test/common/ftr_provider_context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { GenericFtrProviderContext, GenericFtrService } from '@kbn/test';

import { services } from './services';

export type FtrProviderContext = GenericFtrProviderContext<typeof services, {}>;
export class FtrService extends GenericFtrService<FtrProviderContext> {}
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,7 +62,6 @@ export interface SendOptions {
* });
* expect(response).eql({ ... your value ... });
*/

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

Expand Down
15 changes: 15 additions & 0 deletions test/common/services/console.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { FtrProviderContext } from '../ftr_provider_context';
import { helpers } from '../../api_integration/apis/console/helpers';
export function ConsoleProvider({ getService }: FtrProviderContext) {
return {
helpers: helpers(getService),
};
}
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
Loading

0 comments on commit 0894c8b

Please sign in to comment.