IDM: Migrates kbn_server to a dev-only package (#146248)

redo of: https://github.com/elastic/kibana/pull/145785 due to failures
when it hit main resulting in a revert.

fix https://github.com/elastic/kibana/issues/145193

Migrates `core/server/test-helpers/kbn_server` to a package
Updates imports across repo

### Checklist

Delete any items that are not applicable to this PR.

- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

Co-authored-by: Christiane (Tina) Heiligers <christiane.heiligers@elastic.co>
This commit is contained in:
Tyler Smalley 2022-11-23 16:48:24 -08:00 committed by GitHub
parent 8e55ec5e6e
commit 56916574ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 706 additions and 343 deletions

1
.github/CODEOWNERS vendored
View file

@ -866,6 +866,7 @@ packages/core/status/core-status-server-internal @elastic/kibana-core
packages/core/status/core-status-server-mocks @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-deprecations-getters @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-http-setup-browser @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-kbn-server @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-so-type-serializer @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-test-utils @elastic/kibana-core
packages/core/theme/core-theme-browser @elastic/kibana-core

View file

@ -733,6 +733,7 @@
"@kbn/ci-stats-performance-metrics": "link:bazel-bin/packages/kbn-ci-stats-performance-metrics",
"@kbn/ci-stats-reporter": "link:bazel-bin/packages/kbn-ci-stats-reporter",
"@kbn/cli-dev-mode": "link:bazel-bin/packages/kbn-cli-dev-mode",
"@kbn/core-test-helpers-kbn-server": "link:bazel-bin/packages/core/test-helpers/core-test-helpers-kbn-server",
"@kbn/dev-cli-errors": "link:bazel-bin/packages/kbn-dev-cli-errors",
"@kbn/dev-cli-runner": "link:bazel-bin/packages/kbn-dev-cli-runner",
"@kbn/dev-proc-runner": "link:bazel-bin/packages/kbn-dev-proc-runner",

View file

@ -173,6 +173,7 @@ filegroup(
"//packages/core/status/core-status-server-mocks:build",
"//packages/core/test-helpers/core-test-helpers-deprecations-getters:build",
"//packages/core/test-helpers/core-test-helpers-http-setup-browser:build",
"//packages/core/test-helpers/core-test-helpers-kbn-server:build",
"//packages/core/test-helpers/core-test-helpers-so-type-serializer:build",
"//packages/core/test-helpers/core-test-helpers-test-utils:build",
"//packages/core/theme/core-theme-browser:build",
@ -538,6 +539,7 @@ filegroup(
"//packages/core/status/core-status-server-mocks:build_types",
"//packages/core/test-helpers/core-test-helpers-deprecations-getters:build_types",
"//packages/core/test-helpers/core-test-helpers-http-setup-browser:build_types",
"//packages/core/test-helpers/core-test-helpers-kbn-server:build_types",
"//packages/core/test-helpers/core-test-helpers-so-type-serializer:build_types",
"//packages/core/test-helpers/core-test-helpers-test-utils:build_types",
"//packages/core/theme/core-theme-browser:build_types",

View file

@ -0,0 +1,121 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
PKG_DIRNAME = "core-test-helpers-kbn-server"
PKG_REQUIRE_NAME = "@kbn/core-test-helpers-kbn-server"
SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
"@npm//lodash",
"@npm//rxjs",
"@npm//supertest",
"//packages/kbn-tooling-log",
"//packages/kbn-utils",
"//packages/kbn-test",
"//packages/kbn-config",
"//packages/core/lifecycle/core-lifecycle-server-internal",
"//packages/core/root/core-root-server-internal",
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//lodash",
"@npm//rxjs",
"@npm//supertest",
"//packages/kbn-tooling-log:npm_module_types",
"//packages/kbn-utils:npm_module_types",
"//packages/kbn-test:npm_module_types",
"//packages/kbn-config:npm_module_types",
"//packages/core/lifecycle/core-lifecycle-server-internal:npm_module_types",
"//packages/core/root/core-root-server-internal:npm_module_types",
]
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)
ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)
ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
tsconfig = ":tsconfig",
)
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
js_library(
name = "npm_module_types",
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":tsc_types"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)
filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)
filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)

View file

@ -0,0 +1,15 @@
# @kbn/core-test-helpers-kbn-server
This package contains Core's server side kbn_server test helpers including:
- createRootWithSettings
- getSupertest
- createRoot
- createRootWithCorePlugins
- createTestServers
- request
and types:
- HttpMethod
- TestElasticsearchUtils
- TestKibanaUtils
- TestUtils

View file

@ -0,0 +1,18 @@
/*
* 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.
*/
export {
createRootWithSettings,
getSupertest,
createRoot,
createRootWithCorePlugins,
createTestServers,
request,
} from './src';
export type { HttpMethod, TestElasticsearchUtils, TestKibanaUtils, TestUtils } from './src';

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/core/test-helpers/core-test-helpers-kbn-server'],
};

View file

@ -0,0 +1,8 @@
{
"type": "shared-common",
"id": "@kbn/core-test-helpers-kbn-server",
"owner": "@elastic/kibana-core",
"devOnly": true,
"runtimeDeps": [],
"typeDeps": [],
}

View file

@ -0,0 +1,9 @@
{
"name": "@kbn/core-test-helpers-kbn-server",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"types": "./target_types/index.d.ts",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,18 @@
/*
* 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.
*/
export {
createRootWithSettings,
getSupertest,
createRoot,
createRootWithCorePlugins,
createTestServers,
request,
} from './create_root';
export type { HttpMethod, TestElasticsearchUtils, TestKibanaUtils, TestUtils } from './create_root';

View file

@ -0,0 +1,15 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}

View file

@ -8,10 +8,10 @@
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import { mockLoggingSystem } from './config_deprecation.test.mocks';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot } from '@kbn/core-test-helpers-kbn-server';
describe('configuration deprecations', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
beforeEach(() => {
jest.clearAllMocks();
@ -24,7 +24,7 @@ describe('configuration deprecations', () => {
});
it('should not log deprecation warnings for default configuration', async () => {
root = kbnTestServer.createRoot();
root = createRoot();
await root.preboot();
await root.setup();

View file

@ -7,13 +7,13 @@
*/
import { Root } from '@kbn/core-root-server-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
describe('Core app routes', () => {
let root: Root;
beforeAll(async function () {
root = kbnTestServer.createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
server: {
@ -32,32 +32,32 @@ describe('Core app routes', () => {
describe('`/{path*}` route', () => {
it('redirects requests to include the basePath', async () => {
const response = await kbnTestServer.request.get(root, '/some-path/').expect(302);
const response = await request.get(root, '/some-path/').expect(302);
expect(response.get('location')).toEqual('/base-path/some-path');
});
it('includes the query in the redirect', async () => {
const response = await kbnTestServer.request.get(root, '/some-path/?foo=bar').expect(302);
const response = await request.get(root, '/some-path/?foo=bar').expect(302);
expect(response.get('location')).toEqual('/base-path/some-path?foo=bar');
});
it('does not redirect if the path starts with `//`', async () => {
await kbnTestServer.request.get(root, '//some-path/').expect(404);
await request.get(root, '//some-path/').expect(404);
});
it('does not redirect if the path does not end with `/`', async () => {
await kbnTestServer.request.get(root, '/some-path').expect(404);
await request.get(root, '/some-path').expect(404);
});
it('does not add the basePath if the path already contains it', async () => {
const response = await kbnTestServer.request.get(root, '/base-path/foo/').expect(302);
const response = await request.get(root, '/base-path/foo/').expect(302);
expect(response.get('location')).toEqual('/base-path/foo');
});
});
describe('`/` route', () => {
it('prevails on the `/{path*}` route', async () => {
const response = await kbnTestServer.request.get(root, '/').expect(302);
const response = await request.get(root, '/').expect(302);
expect(response.get('location')).toEqual('/base-path/app/home');
});
});

View file

@ -7,18 +7,23 @@
*/
import { Root } from '@kbn/core-root-server-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
request,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
describe('default route provider', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
});
esServer = await startES();
root = kbnTestServer.createRootWithCorePlugins({
root = createRootWithCorePlugins({
server: {
basePath: '/hello',
},
@ -35,7 +40,7 @@ describe('default route provider', () => {
});
it('redirects to the configured default route respecting basePath', async function () {
const { status, header } = await kbnTestServer.request.get(root, '/');
const { status, header } = await request.get(root, '/');
expect(status).toEqual(302);
expect(header).toMatchObject({
@ -52,13 +57,13 @@ describe('default route provider', () => {
];
for (const url of invalidRoutes) {
await kbnTestServer.request
await request
.post(root, '/api/kibana/settings/defaultRoute')
.send({ value: url })
.expect(400);
}
const { status, header } = await kbnTestServer.request.get(root, '/');
const { status, header } = await request.get(root, '/');
expect(status).toEqual(302);
expect(header).toMatchObject({
location: '/hello/app/home',
@ -66,12 +71,12 @@ describe('default route provider', () => {
});
it('consumes valid values', async function () {
await kbnTestServer.request
await request
.post(root, '/api/kibana/settings/defaultRoute')
.send({ value: '/valid' })
.expect(200);
const { status, header } = await kbnTestServer.request.get(root, '/');
const { status, header } = await request.get(root, '/');
expect(status).toEqual(302);
expect(header).toMatchObject({
location: '/hello/valid',

View file

@ -7,13 +7,13 @@
*/
import { Root } from '@kbn/core-root-server-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
describe('Platform assets', function () {
let root: Root;
beforeAll(async function () {
root = kbnTestServer.createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
});
@ -28,18 +28,18 @@ describe('Platform assets', function () {
});
it('exposes static assets', async () => {
await kbnTestServer.request.get(root, '/ui/favicons/favicon.svg').expect(200);
await request.get(root, '/ui/favicons/favicon.svg').expect(200);
});
it('returns 404 if not found', async function () {
await kbnTestServer.request.get(root, '/ui/favicons/not-a-favicon.svg').expect(404);
await request.get(root, '/ui/favicons/not-a-favicon.svg').expect(404);
});
it('does not expose folder content', async function () {
await kbnTestServer.request.get(root, '/ui/favicons/').expect(403);
await request.get(root, '/ui/favicons/').expect(403);
});
it('does not allow file tree traversing', async function () {
await kbnTestServer.request.get(root, '/ui/../../../../../README.md').expect(404);
await request.get(root, '/ui/../../../../../README.md').expect(404);
});
});

View file

@ -14,9 +14,9 @@ import { Root } from '@kbn/core-root-server-internal';
import {
createRootWithCorePlugins,
createTestServers,
TestElasticsearchUtils,
TestKibanaUtils,
} from '../../../test_helpers/kbn_server';
type TestElasticsearchUtils,
type TestKibanaUtils,
} from '@kbn/core-test-helpers-kbn-server';
describe('elasticsearch clients', () => {
let esServer: TestElasticsearchUtils;

View file

@ -8,9 +8,9 @@
import {
createTestServers,
TestElasticsearchUtils,
TestKibanaUtils,
} from '../../../test_helpers/kbn_server';
type TestElasticsearchUtils,
type TestKibanaUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { isInlineScriptingEnabled } from '@kbn/core-elasticsearch-server-internal';
describe('isInlineScriptingEnabled', () => {

View file

@ -7,7 +7,14 @@
*/
import { ExecutionContextContainer } from '@kbn/core-execution-context-browser-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import {
createRoot,
createTestServers,
createRootWithCorePlugins,
request as kbnServerRequest,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { RequestHandlerContext } from '../..';
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@ -27,10 +34,10 @@ const withUtf8CharsContext = {
};
describe('trace', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let root: ReturnType<typeof kbnTestServer.createRoot>;
let esServer: TestElasticsearchUtils;
let root: ReturnType<typeof createRoot>;
beforeAll(async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: jest.setTimeout,
});
esServer = await startES();
@ -41,7 +48,7 @@ describe('trace', () => {
});
beforeEach(async () => {
root = kbnTestServer.createRootWithCorePlugins({
root = createRootWithCorePlugins({
plugins: { initialize: false },
server: {
requestId: {
@ -74,7 +81,7 @@ describe('trace', () => {
await root.start();
const myOpaqueId = 'my-opaque-id';
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', myOpaqueId)
.expect(200);
@ -97,7 +104,7 @@ describe('trace', () => {
await root.start();
const myOpaqueId = 'my-opaque-id';
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', myOpaqueId)
.expect(200);
@ -119,7 +126,7 @@ describe('trace', () => {
await root.start();
const response = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const response = await kbnServerRequest.get(root, '/execution-context').expect(200);
const header = response.body['x-opaque-id'];
expect(header).toEqual(expect.any(String));
@ -138,7 +145,7 @@ describe('trace', () => {
await root.start();
const response = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const response = await kbnServerRequest.get(root, '/execution-context').expect(200);
const header = response.body['x-opaque-id'];
expect(header).toEqual(expect.any(String));
@ -164,7 +171,7 @@ describe('trace', () => {
await root.start();
const myOpaqueId = 'my-opaque-id';
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', myOpaqueId)
.expect(200);
@ -174,9 +181,9 @@ describe('trace', () => {
});
describe('ExecutionContext Service is disabled', () => {
let rootExecutionContextDisabled: ReturnType<typeof kbnTestServer.createRoot>;
let rootExecutionContextDisabled: ReturnType<typeof createRoot>;
beforeEach(async () => {
rootExecutionContextDisabled = kbnTestServer.createRootWithCorePlugins({
rootExecutionContextDisabled = createRootWithCorePlugins({
execution_context: { enabled: false },
plugins: { initialize: false },
server: {
@ -205,7 +212,7 @@ describe('trace', () => {
await rootExecutionContextDisabled.start();
const myOpaqueId = 'my-opaque-id';
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(rootExecutionContextDisabled, '/execution-context')
.set('x-opaque-id', myOpaqueId)
.expect(200);
@ -234,7 +241,7 @@ describe('trace', () => {
await rootExecutionContextDisabled.start();
const myOpaqueId = 'my-opaque-id';
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(rootExecutionContextDisabled, '/execution-context')
.set('x-opaque-id', myOpaqueId)
.expect(200);
@ -258,7 +265,7 @@ describe('trace', () => {
});
await root.start();
const response = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const response = await kbnServerRequest.get(root, '/execution-context').expect(200);
expect(response.body).toEqual(parentContext);
});
@ -274,7 +281,7 @@ describe('trace', () => {
});
await root.start();
const response = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const response = await kbnServerRequest.get(root, '/execution-context').expect(200);
expect(response.body).toEqual(parentContext);
});
@ -291,8 +298,8 @@ describe('trace', () => {
});
await root.start();
const responseA = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const responseB = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const responseA = await kbnServerRequest.get(root, '/execution-context').expect(200);
const responseB = await kbnServerRequest.get(root, '/execution-context').expect(200);
expect(responseA.body).toEqual({ ...parentContext, id: '42' });
expect(responseB.body).toEqual({ ...parentContext, id: '43' });
@ -311,9 +318,9 @@ describe('trace', () => {
});
await root.start();
const responseA = kbnTestServer.request.get(root, '/execution-context');
const responseB = kbnTestServer.request.get(root, '/execution-context');
const responseC = kbnTestServer.request.get(root, '/execution-context');
const responseA = kbnServerRequest.get(root, '/execution-context');
const responseB = kbnServerRequest.get(root, '/execution-context');
const responseC = kbnServerRequest.get(root, '/execution-context');
const [{ body: bodyA }, { body: bodyB }, { body: bodyC }] = await Promise.all([
responseA,
@ -341,13 +348,13 @@ describe('trace', () => {
});
await root.start();
const responseA = kbnTestServer.request
const responseA = kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', 'req-1');
const responseB = kbnTestServer.request
const responseB = kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', 'req-2');
const responseC = kbnTestServer.request
const responseC = kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', 'req-3');
@ -371,7 +378,7 @@ describe('trace', () => {
);
await root.start();
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set(new ExecutionContextContainer(parentContext).toHeader())
.expect(200);
@ -391,7 +398,7 @@ describe('trace', () => {
});
await root.start();
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', 'utf-test')
.set(new ExecutionContextContainer(withUtf8CharsContext).toHeader())
@ -453,7 +460,7 @@ describe('trace', () => {
});
await root.start();
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set(new ExecutionContextContainer(parentContext).toHeader())
.expect(200);
@ -480,7 +487,7 @@ describe('trace', () => {
await root.start();
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set(new ExecutionContextContainer(parentContext).toHeader())
.expect(200);
@ -502,7 +509,7 @@ describe('trace', () => {
await root.start();
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set(new ExecutionContextContainer(parentContext).toHeader())
.expect(200);
@ -525,7 +532,7 @@ describe('trace', () => {
await root.start();
const myOpaqueId = 'my-opaque-id';
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', myOpaqueId)
.expect(200);
@ -549,7 +556,7 @@ describe('trace', () => {
await root.start();
const myOpaqueId = 'my-opaque-id';
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set('x-opaque-id', myOpaqueId)
.expect(200);
@ -578,7 +585,7 @@ describe('trace', () => {
await root.start();
const response = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const response = await kbnServerRequest.get(root, '/execution-context').expect(200);
const header = response.body['x-opaque-id'];
expect(header).toContain('kibana:test-type:test-name:42');
@ -597,7 +604,7 @@ describe('trace', () => {
});
await root.start();
const response = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const response = await kbnServerRequest.get(root, '/execution-context').expect(200);
expect(response.body).toEqual(parentContext);
});
@ -623,7 +630,7 @@ describe('trace', () => {
});
await root.start();
const response = await kbnTestServer.request.get(root, '/execution-context').expect(200);
const response = await kbnServerRequest.get(root, '/execution-context').expect(200);
expect(response.body).toEqual({ child: nestedContext, ...parentContext });
});
@ -648,7 +655,7 @@ describe('trace', () => {
await root.start();
const response = await kbnTestServer.request
const response = await kbnServerRequest
.get(root, '/execution-context')
.set(new ExecutionContextContainer(parentContext).toHeader())
.expect(200);

View file

@ -10,7 +10,7 @@ import { MockElasticsearchClient } from './core_service.test.mocks';
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { errors } from '@elastic/elasticsearch';
import type { InternalElasticsearchServiceStart } from '@kbn/core-elasticsearch-server-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
const cookieOptions = {
name: 'sid',
@ -32,9 +32,9 @@ describe('http service', () => {
});
describe('auth', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
beforeEach(async () => {
root = kbnTestServer.createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
});
@ -57,7 +57,7 @@ describe('http service', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/is-auth').expect(200, { isAuthenticated: true });
await request.get(root, '/is-auth').expect(200, { isAuthenticated: true });
});
it('returns false if has not been authenticated', async () => {
@ -73,7 +73,7 @@ describe('http service', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/is-auth').expect(200, { isAuthenticated: false });
await request.get(root, '/is-auth').expect(200, { isAuthenticated: false });
});
it('returns false if no authentication mechanism has been registered', async () => {
@ -87,7 +87,7 @@ describe('http service', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/is-auth').expect(200, { isAuthenticated: false });
await request.get(root, '/is-auth').expect(200, { isAuthenticated: false });
});
it('returns true if authenticated on a route with "optional" auth', async () => {
@ -102,7 +102,7 @@ describe('http service', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/is-auth').expect(200, { isAuthenticated: true });
await request.get(root, '/is-auth').expect(200, { isAuthenticated: true });
});
it('returns false if not authenticated on a route with "optional" auth', async () => {
@ -118,7 +118,7 @@ describe('http service', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/is-auth').expect(200, { isAuthenticated: false });
await request.get(root, '/is-auth').expect(200, { isAuthenticated: false });
});
});
describe('#get()', () => {
@ -140,9 +140,7 @@ describe('http service', () => {
await root.start();
await kbnTestServer.request
.get(root, '/get-auth')
.expect(200, { state: user, status: 'authenticated' });
await request.get(root, '/get-auth').expect(200, { state: user, status: 'authenticated' });
});
it('returns correct authentication unknown status', async () => {
@ -155,7 +153,7 @@ describe('http service', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/get-auth').expect(200, { status: 'unknown' });
await request.get(root, '/get-auth').expect(200, { status: 'unknown' });
});
it('returns correct unauthenticated status', async () => {
@ -172,9 +170,7 @@ describe('http service', () => {
await root.start();
await kbnTestServer.request
.get(root, '/get-auth')
.expect(200, { status: 'unauthenticated' });
await request.get(root, '/get-auth').expect(200, { status: 'unauthenticated' });
expect(authenticate).not.toHaveBeenCalled();
});
@ -182,10 +178,10 @@ describe('http service', () => {
});
describe('elasticsearch client', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
beforeEach(async () => {
root = kbnTestServer.createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
});
@ -230,7 +226,7 @@ describe('http service', () => {
const coreStart = await root.start();
elasticsearch = coreStart.elasticsearch;
const { header } = await kbnTestServer.request.get(root, '/new-platform/').expect(401);
const { header } = await request.get(root, '/new-platform/').expect(401);
expect(header['www-authenticate']).toEqual('content');
});
@ -266,7 +262,7 @@ describe('http service', () => {
const coreStart = await root.start();
elasticsearch = coreStart.elasticsearch;
const { header } = await kbnTestServer.request.get(root, '/new-platform/').expect(401);
const { header } = await request.get(root, '/new-platform/').expect(401);
expect(header['www-authenticate']).toEqual('Basic realm="Authorization Required"');
});
@ -313,7 +309,7 @@ describe('http service', () => {
const coreStart = await root.start();
elasticsearch = coreStart.elasticsearch;
const { body } = await kbnTestServer.request.get(root, '/new-platform/').expect(400);
const { body } = await request.get(root, '/new-platform/').expect(400);
expect(body.message).toMatch('[error_type]: error_reason');
});

View file

@ -7,13 +7,13 @@
*/
import type { IRouter, RouteConfigOptions, HttpAuth } from '@kbn/core-http-server';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
describe('http auth', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
beforeEach(async () => {
root = kbnTestServer.createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
});
@ -53,7 +53,7 @@ describe('http auth', () => {
registerRoute(router, auth, true);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: true });
await request.get(root, '/route').expect(200, { authenticated: true });
});
it('blocks access when auth returns `notHandled`', async () => {
@ -66,7 +66,7 @@ describe('http auth', () => {
registerRoute(router, auth, true);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(401);
await request.get(root, '/route').expect(401);
});
it('blocks access when auth returns `unauthorized`', async () => {
@ -79,7 +79,7 @@ describe('http auth', () => {
registerRoute(router, auth, true);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(401);
await request.get(root, '/route').expect(401);
});
});
describe('when authRequired is `false`', () => {
@ -93,7 +93,7 @@ describe('http auth', () => {
registerRoute(router, auth, false);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
it('allows anonymous access when auth returns `notHandled`', async () => {
@ -106,7 +106,7 @@ describe('http auth', () => {
registerRoute(router, auth, false);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
it('allows anonymous access when auth returns `unauthorized`', async () => {
@ -119,7 +119,7 @@ describe('http auth', () => {
registerRoute(router, auth, false);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
});
describe('when authRequired is `optional`', () => {
@ -133,7 +133,7 @@ describe('http auth', () => {
registerRoute(router, auth, 'optional');
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: true });
await request.get(root, '/route').expect(200, { authenticated: true });
});
it('allows anonymous access when auth returns `notHandled`', async () => {
@ -146,7 +146,7 @@ describe('http auth', () => {
registerRoute(router, auth, 'optional');
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
it('allows anonymous access when auth returns `unauthorized`', async () => {
@ -159,7 +159,7 @@ describe('http auth', () => {
registerRoute(router, auth, 'optional');
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
});
});
@ -173,7 +173,7 @@ describe('http auth', () => {
registerRoute(router, auth, true);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
it('allow anonymous access to resources when `authRequired` is `false`', async () => {
@ -184,7 +184,7 @@ describe('http auth', () => {
registerRoute(router, auth, false);
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
it('allow anonymous access to resources when `authRequired` is `optional`', async () => {
@ -195,7 +195,7 @@ describe('http auth', () => {
registerRoute(router, auth, 'optional');
await root.start();
await kbnTestServer.request.get(root, '/route').expect(200, { authenticated: false });
await request.get(root, '/route').expect(200, { authenticated: false });
});
});
});

View file

@ -7,7 +7,7 @@
*/
import { schema } from '@kbn/config-schema';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
describe('request logging', () => {
let mockConsoleLog: jest.SpyInstance;
@ -27,7 +27,7 @@ describe('request logging', () => {
describe('http server response logging', () => {
describe('configuration', () => {
it('does not log with a default config', async () => {
const root = kbnTestServer.createRoot({
const root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
});
@ -42,14 +42,14 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/ping').expect(200, 'pong');
await request.get(root, '/ping').expect(200, 'pong');
expect(mockConsoleLog).not.toHaveBeenCalled();
await root.shutdown();
});
it('logs at the correct level and with the correct context', async () => {
const root = kbnTestServer.createRoot({
const root = createRoot({
logging: {
appenders: {
'test-console': {
@ -84,7 +84,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/ping').expect(200, 'pong');
await request.get(root, '/ping').expect(200, 'pong');
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
const [level, logger] = mockConsoleLog.mock.calls[0][0].split('|');
expect(level).toBe('DEBUG');
@ -95,7 +95,7 @@ describe('request logging', () => {
});
describe('content', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
const config = {
logging: {
appenders: {
@ -122,7 +122,7 @@ describe('request logging', () => {
};
beforeEach(() => {
root = kbnTestServer.createRoot(config);
root = createRoot(config);
});
afterEach(async () => {
@ -141,7 +141,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/ping').expect(200, 'pong');
await request.get(root, '/ping').expect(200, 'pong');
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
const [, , message, meta] = mockConsoleLog.mock.calls[0][0].split('|');
// some of the contents of the message are variable based on environment, such as
@ -174,7 +174,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request
await request
.post(root, '/ping')
.set('Content-Type', 'application/json')
.send({ message: 'hi' })
@ -196,7 +196,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/b').expect(404);
await request.get(root, '/b').expect(404);
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
const [, , message, meta] = mockConsoleLog.mock.calls[0][0].split('|');
// some of the contents of the message are variable based on environment, such as
@ -217,7 +217,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/ping').query({ hey: 'ya' }).expect(200, 'pong');
await request.get(root, '/ping').query({ hey: 'ya' }).expect(200, 'pong');
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
const [, , message, meta] = mockConsoleLog.mock.calls[0][0].split('|');
expect(message.includes('GET /ping?hey=ya 200')).toBe(true);
@ -236,7 +236,7 @@ describe('request logging', () => {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/ping').expect(200, 'pong');
const response = await request.get(root, '/ping').expect(200, 'pong');
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
const [, , , meta] = mockConsoleLog.mock.calls[0][0].split('|');
expect(JSON.parse(meta).http.response.body.bytes).toBe(response.text.length);
@ -255,7 +255,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/ping').set('foo', 'hello').expect(200);
await request.get(root, '/ping').set('foo', 'hello').expect(200);
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
const [, , , meta] = mockConsoleLog.mock.calls[0][0].split('|');
expect(JSON.parse(meta).http.request.headers.foo).toBe('hello');
@ -284,7 +284,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request
await request
.post(root, '/ping')
.set('content-type', 'application/json')
.set('authorization', 'abc')
@ -296,7 +296,7 @@ describe('request logging', () => {
});
it('filters sensitive request headers when RewriteAppender is configured', async () => {
root = kbnTestServer.createRoot({
root = createRoot({
logging: {
appenders: {
'test-console': {
@ -352,7 +352,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request
await request
.post(root, '/ping')
.set('content-type', 'application/json')
.set('authorization', 'abc')
@ -386,7 +386,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request
await request
.post(root, '/ping')
.set('Content-Type', 'application/json')
.send({ message: 'hi' })
@ -397,7 +397,7 @@ describe('request logging', () => {
});
it('filters sensitive response headers when RewriteAppender is configured', async () => {
root = kbnTestServer.createRoot({
root = createRoot({
logging: {
appenders: {
'test-console': {
@ -452,7 +452,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request
await request
.post(root, '/ping')
.set('Content-Type', 'application/json')
.send({ message: 'hi' })
@ -475,7 +475,7 @@ describe('request logging', () => {
);
await root.start();
await kbnTestServer.request.get(root, '/ping').set('user-agent', 'world').expect(200);
await request.get(root, '/ping').set('user-agent', 'world').expect(200);
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
const [, , , meta] = mockConsoleLog.mock.calls[0][0].split('|');
expect(JSON.parse(meta).http.request.headers['user-agent']).toBe('world');

View file

@ -7,7 +7,7 @@
*/
import { schema } from '@kbn/config-schema';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
describe('http resources service', () => {
describe('register', () => {
@ -18,12 +18,12 @@ describe('http resources service', () => {
function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
describe(`with disableUnsafeEval=${disableUnsafeEval}`, () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
const defaultCspRules = disableUnsafeEval
? `script-src 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'`
: `script-src 'self' 'unsafe-eval'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'`;
beforeEach(async () => {
root = kbnTestServer.createRoot({
root = createRoot({
csp: { disableUnsafeEval },
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
@ -46,7 +46,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/render-core').expect(200);
const response = await request.get(root, '/render-core').expect(200);
expect(response.text.length).toBeGreaterThan(0);
});
@ -61,7 +61,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/render-core').expect(200);
const response = await request.get(root, '/render-core').expect(200);
expect(response.header['content-security-policy']).toBe(defaultCspRules);
});
@ -81,7 +81,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/render-core').expect(200);
const response = await request.get(root, '/render-core').expect(200);
expect(response.header['content-security-policy']).toBe(defaultCspRules);
expect(response.header['x-kibana']).toBe('42');
@ -107,7 +107,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/render-html').expect(200);
const response = await request.get(root, '/render-html').expect(200);
expect(response.text).toBe(htmlBody);
expect(response.header['content-type']).toBe('text/html; charset=utf-8');
@ -124,7 +124,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/render-js').expect(200);
const response = await request.get(root, '/render-js').expect(200);
expect(response.text).toBe(jsBody);
expect(response.header['content-type']).toBe('text/javascript; charset=utf-8');
@ -148,7 +148,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/render-html').expect(200);
const response = await request.get(root, '/render-html').expect(200);
expect(response.header['content-security-policy']).toBe(defaultCspRules);
});
@ -170,7 +170,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request.get(root, '/render-core').expect(200);
const response = await request.get(root, '/render-core').expect(200);
expect(response.header['content-security-policy']).toBe(defaultCspRules);
expect(response.header['x-kibana']).toBe('42');
@ -192,9 +192,7 @@ function applyTestsWithDisableUnsafeEvalSetTo(disableUnsafeEval: boolean) {
);
await root.start();
const response = await kbnTestServer.request
.get(root, '/render-js-with-param/42')
.expect(200);
const response = await request.get(root, '/render-js-with-param/42').expect(200);
expect(response.text).toBe('window.alert(42);');
});

View file

@ -7,12 +7,12 @@
*/
import type { LoggerContextConfigInput } from '@kbn/core-logging-server';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot as createkbnTestServerRoot } from '@kbn/core-test-helpers-kbn-server';
import { InternalCoreSetup } from '@kbn/core-lifecycle-server-internal';
import { Subject } from 'rxjs';
function createRoot() {
return kbnTestServer.createRoot({
return createkbnTestServerRoot({
logging: {
appenders: {
'test-console': {
@ -149,7 +149,7 @@ describe('logging service', () => {
beforeAll(async () => {
mockConsoleLog = jest.spyOn(global.console, 'log');
root = kbnTestServer.createRoot();
root = createRoot();
await root.preboot();
setup = await root.setup();

View file

@ -10,14 +10,14 @@ import { join } from 'path';
import { rm, mkdtemp, readFile, readdir } from 'fs/promises';
import moment from 'moment-timezone';
import { getNextRollingTime } from '@kbn/core-logging-server-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot as createkbnTestServerRoot } from '@kbn/core-test-helpers-kbn-server';
const flushDelay = 250;
const delay = (waitInMs: number) => new Promise((resolve) => setTimeout(resolve, waitInMs));
const flush = async () => delay(flushDelay);
function createRoot(appenderConfig: any) {
return kbnTestServer.createRoot({
return createkbnTestServerRoot({
logging: {
appenders: {
'rolling-file': appenderConfig,

View file

@ -6,10 +6,10 @@
* Side Public License, v 1.
*/
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot as createkbnTestServerRoot } from '@kbn/core-test-helpers-kbn-server';
function createRootWithRoles(roles: string[]) {
return kbnTestServer.createRoot({
return createkbnTestServerRoot({
node: {
roles,
},

View file

@ -12,9 +12,13 @@ import { REPO_ROOT } from '@kbn/utils';
import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import type { InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import { Root } from '@kbn/core-root-server-internal';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version;
const logFilePath = path.join(__dirname, '7.7.2_xpack_100k.log');
@ -28,7 +32,7 @@ async function removeLogFile() {
const UNUSED_SO_COUNT = 4;
describe('migration from 7.7.2-xpack with 100k objects', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let coreStart: InternalCoreStart;
let esClient: ElasticsearchClient;
@ -38,7 +42,7 @@ describe('migration from 7.7.2-xpack with 100k objects', () => {
});
const startServers = async ({ dataArchive, oss }: { dataArchive: string; oss: boolean }) => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(600000),
settings: {
es: {
@ -48,7 +52,7 @@ describe('migration from 7.7.2-xpack with 100k objects', () => {
},
});
root = kbnTestServer.createRootWithCorePlugins(
root = createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -9,8 +9,12 @@
import Path from 'path';
import fs from 'fs/promises';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '@kbn/core-root-server-internal';
import {
createRootWithCorePlugins,
createTestServers,
TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
const logFilePath = Path.join(__dirname, '7_13_failed_action_tasks.log');
@ -20,16 +24,16 @@ async function removeLogFile() {
}
describe('migration from 7.13 to 7.14+ with many failed action_tasks', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let startES: () => Promise<kbnTestServer.TestElasticsearchUtils>;
let startES: () => Promise<TestElasticsearchUtils>;
beforeAll(async () => {
await removeLogFile();
});
beforeEach(() => {
({ startES } = kbnTestServer.createTestServers({
({ startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -109,7 +113,7 @@ describe('migration from 7.13 to 7.14+ with many failed action_tasks', () => {
});
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -13,10 +13,14 @@ import { Env } from '@kbn/config';
import { REPO_ROOT } from '@kbn/utils';
import { getEnvOptions } from '@kbn/config-mocks';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '@kbn/core-root-server-internal';
import { SearchTotalHits } from '@elastic/elasticsearch/lib/api/types';
import { getMigrationDocLink } from './test_utils';
import {
createRootWithCorePlugins,
TestElasticsearchUtils,
createTestServers as createkbnServerTestServers,
} from '@kbn/core-test-helpers-kbn-server';
const migrationDocLink = getMigrationDocLink().resolveMigrationFailures;
const logFilePath = Path.join(__dirname, '7_13_corrupt_transform_failures.log');
@ -29,7 +33,7 @@ async function removeLogFile() {
}
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -148,7 +152,7 @@ describe('migration v2', () => {
});
function createTestServers() {
return kbnTestServer.createTestServers({
return createkbnServerTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -186,7 +190,7 @@ function createTestServers() {
}
function createRoot(discardCorruptObjects?: string) {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -13,8 +13,12 @@ import { Env } from '@kbn/config';
import { REPO_ROOT } from '@kbn/utils';
import { getEnvOptions } from '@kbn/config-mocks';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '@kbn/core-root-server-internal';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
const logFilePath = Path.join(__dirname, '7_13_unknown_types.log');
@ -24,16 +28,16 @@ async function removeLogFile() {
}
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let startES: () => Promise<kbnTestServer.TestElasticsearchUtils>;
let startES: () => Promise<TestElasticsearchUtils>;
beforeAll(async () => {
await removeLogFile();
});
beforeEach(() => {
({ startES } = kbnTestServer.createTestServers({
({ startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -129,7 +133,7 @@ describe('migration v2', () => {
});
function createRoot(discardUnknownObjects?: string) {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -13,7 +13,7 @@ import { errors } from '@elastic/elasticsearch';
import type { TaskEither } from 'fp-ts/lib/TaskEither';
import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../../test_helpers/kbn_server';
import { createTestServers, type TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server';
import {
bulkOverwriteTransformedDocuments,
closePit,
@ -44,7 +44,7 @@ import {
MIGRATION_CLIENT_OPTIONS,
} from '@kbn/core-saved-objects-migration-server-internal';
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -54,7 +54,7 @@ const { startES } = kbnTestServer.createTestServers({
},
},
});
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
describe('migration actions', () => {
let client: ElasticsearchClient;

View file

@ -9,7 +9,11 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import { Root } from '@kbn/core-root-server-internal';
import type { ElasticsearchClient } from '../../../..';
import * as kbnTestServer from '../../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import {
isWriteBlockException,
isClusterShardLimitExceeded,
@ -17,7 +21,7 @@ import {
setWriteBlock,
} from '@kbn/core-saved-objects-migration-server-internal';
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
});
@ -25,11 +29,11 @@ describe('Elasticsearch Errors', () => {
let root: Root;
let start: InternalCoreStart;
let client: ElasticsearchClient;
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
beforeAll(async () => {
esServer = await startES();
root = kbnTestServer.createRootWithCorePlugins({
root = createRootWithCorePlugins({
server: {
basePath: '/foo',
},

View file

@ -9,7 +9,11 @@
import Path from 'path';
import fs from 'fs/promises';
import JSON5 from 'json5';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Env } from '@kbn/config';
@ -52,16 +56,16 @@ async function fetchDocuments(esClient: ElasticsearchClient, index: string) {
const assertMigratedDocuments = (arr: any[], target: any[]) => target.every((v) => arr.includes(v));
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let startES: () => Promise<kbnTestServer.TestElasticsearchUtils>;
let startES: () => Promise<TestElasticsearchUtils>;
beforeAll(async () => {
await removeLogFile();
});
beforeEach(() => {
({ startES } = kbnTestServer.createTestServers({
({ startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -133,7 +137,7 @@ describe('migration v2', () => {
});
function createRoot(options: { maxBatchSizeBytes?: number }) {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -9,7 +9,11 @@
import Path from 'path';
import fs from 'fs/promises';
import JSON5 from 'json5';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { retryAsync } from '@kbn/core-saved-objects-migration-server-mocks';
import { Root } from '@kbn/core-root-server-internal';
@ -21,16 +25,16 @@ async function removeLogFile() {
}
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let startES: () => Promise<kbnTestServer.TestElasticsearchUtils>;
let startES: () => Promise<TestElasticsearchUtils>;
beforeAll(async () => {
await removeLogFile();
});
beforeEach(() => {
({ startES } = kbnTestServer.createTestServers({
({ startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -84,7 +88,7 @@ describe('migration v2', () => {
});
function createRoot(options: { maxBatchSizeBytes?: number }) {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -9,20 +9,24 @@
import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server';
import { getMigrationHash } from '@kbn/core-test-helpers-so-type-serializer';
import { Root } from '@kbn/core-root-server-internal';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
describe('checking migration metadata changes on all registered SO types', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let typeRegistry: ISavedObjectTypeRegistry;
beforeAll(async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
});
esServer = await startES();
root = kbnTestServer.createRootWithCorePlugins({}, { oss: false });
root = createRootWithCorePlugins({}, { oss: false });
await root.preboot();
await root.setup();
const coreStart = await root.start();

View file

@ -10,7 +10,11 @@ import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import JSON5 from 'json5';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
import { getMigrationDocLink } from './test_utils';
@ -26,7 +30,7 @@ async function removeLogFile() {
}
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,
@ -57,7 +61,7 @@ function createRoot() {
}
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -76,7 +80,7 @@ describe('migration v2', () => {
});
it('clean ups if migration fails', async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {

View file

@ -9,7 +9,11 @@
import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
import { getMigrationDocLink } from './test_utils';
@ -24,7 +28,7 @@ async function removeLogFile() {
}
describe('migration v2 with corrupt saved object documents', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -43,7 +47,7 @@ describe('migration v2 with corrupt saved object documents', () => {
});
it('collects corrupt saved object documents across batches', async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -157,7 +161,7 @@ describe('migration v2 with corrupt saved object documents', () => {
});
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -9,7 +9,11 @@
import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
const logFilePath = Path.join(__dirname, 'corrupt_outdated_docs.log');
@ -22,7 +26,7 @@ async function removeLogFile() {
}
describe('migration v2 with corrupt saved object documents', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -41,7 +45,7 @@ describe('migration v2 with corrupt saved object documents', () => {
});
it.skip('collects corrupt saved object documents across batches', async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -149,7 +153,7 @@ describe('migration v2 with corrupt saved object documents', () => {
});
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -9,7 +9,11 @@
import Path from 'path';
import fs from 'fs/promises';
import JSON5 from 'json5';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { LogRecord } from '@kbn/logging';
@ -24,7 +28,7 @@ async function removeLogFile() {
await fs.unlink(logFilePath).catch(() => void 0);
}
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -39,7 +43,7 @@ const { startES } = kbnTestServer.createTestServers({
});
function createKbnRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,
@ -79,7 +83,7 @@ const getClusterRoutingAllocations = (settings: Record<string, any>) => {
[...routingAllocations].every((s: string) => s === 'all')
); // if set, only allow 'all';
};
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
async function updateRoutingAllocations(
esClient: ElasticsearchClient,

View file

@ -15,7 +15,11 @@ import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import { Root } from '@kbn/core-root-server-internal';
@ -57,13 +61,13 @@ describe('migrating from 7.3.0-xpack which used v1 migrations', () => {
const migratedIndex = `.kibana_${kibanaVersion}_001`;
const originalIndex = `.kibana_1`; // v1 migrations index
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let coreStart: InternalCoreStart;
let esClient: ElasticsearchClient;
const startServers = async ({ dataArchive, oss }: { dataArchive: string; oss: boolean }) => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -73,7 +77,7 @@ describe('migrating from 7.3.0-xpack which used v1 migrations', () => {
},
});
root = kbnTestServer.createRootWithCorePlugins(
root = createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -14,7 +14,11 @@ import { REPO_ROOT } from '@kbn/utils';
import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import { Root } from '@kbn/core-root-server-internal';
@ -57,13 +61,13 @@ describe('migrating from the same Kibana version that used v1 migrations', () =>
const originalIndex = `.kibana_1`; // v1 migrations index
const migratedIndex = `.kibana_${kibanaVersion}_001`;
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let coreStart: InternalCoreStart;
let esClient: ElasticsearchClient;
const startServers = async ({ dataArchive, oss }: { dataArchive: string; oss: boolean }) => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -73,7 +77,7 @@ describe('migrating from the same Kibana version that used v1 migrations', () =>
},
});
root = kbnTestServer.createRootWithCorePlugins(
root = createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -10,7 +10,11 @@ import Path from 'path';
import del from 'del';
import { kibanaServerTestUser } from '@kbn/test';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRoot as createkbnTestServerRoot,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Root } from '@kbn/core-root-server-internal';
@ -59,7 +63,7 @@ interface RootConfig {
}
function createRoot({ logFileName, hosts }: RootConfig) {
return kbnTestServer.createRoot({
return createkbnTestServerRoot({
elasticsearch: {
hosts,
username: kibanaServerTestUser.username,
@ -91,7 +95,7 @@ function createRoot({ logFileName, hosts }: RootConfig) {
}
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
const migratedIndex = `.kibana_${pkg.version}_001`;
@ -114,7 +118,7 @@ describe('migration v2', () => {
});
it('migrates saved objects normally with multiple ES nodes', async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {

View file

@ -11,7 +11,11 @@ import del from 'del';
import { esTestConfig, kibanaServerTestUser } from '@kbn/test';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import type { SavedObjectsType } from '@kbn/core-saved-objects-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createTestServers,
createRoot as createkbnTestServerRoot,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Root } from '@kbn/core-root-server-internal';
@ -59,7 +63,7 @@ interface CreateRootConfig {
}
async function createRoot({ logFileName }: CreateRootConfig) {
const root = kbnTestServer.createRoot({
const root = createkbnTestServerRoot({
elasticsearch: {
hosts: [esTestConfig.getUrl()],
username: kibanaServerTestUser.username,
@ -103,7 +107,7 @@ async function createRoot({ logFileName }: CreateRootConfig) {
jest.setTimeout(15 * 60 * 1000);
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let rootA: Root;
let rootB: Root;
let rootC: Root;
@ -139,7 +143,7 @@ describe('migration v2', () => {
logFileName: Path.join(__dirname, `${LOG_FILE_PREFIX}_C.log`),
});
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {

View file

@ -10,7 +10,11 @@ import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Root } from '@kbn/core-root-server-internal';
@ -23,7 +27,7 @@ async function removeLogFile() {
}
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -43,7 +47,7 @@ describe('migration v2', () => {
it('migrates the documents to the highest version', async () => {
const migratedIndex = `.kibana_${pkg.version}_001`;
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -91,7 +95,7 @@ describe('migration v2', () => {
});
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -10,7 +10,11 @@ import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Root } from '@kbn/core-root-server-internal';
import { deterministicallyRegenerateObjectId } from '@kbn/core-saved-objects-migration-server-internal';
@ -58,7 +62,7 @@ async function fetchDocs(esClient: ElasticsearchClient, index: string) {
}
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,
@ -90,7 +94,7 @@ function createRoot() {
// FAILING: https://github.com/elastic/kibana/issues/98351
describe('migration v2', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -110,7 +114,7 @@ describe('migration v2', () => {
it('rewrites id deterministically for SO with namespaceType: "multiple" and "multiple-isolated"', async () => {
const migratedIndex = `.kibana_${pkg.version}_001`;
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {

View file

@ -10,7 +10,11 @@ import Path from 'path';
import Fs from 'fs';
import Util from 'util';
import { firstValueFrom } from 'rxjs';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
const logFilePath = Path.join(__dirname, 'cleanup.log');
@ -22,7 +26,7 @@ async function removeLogFile() {
}
function createRoot({ skipMigration }: { skipMigration: boolean }) {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: skipMigration,
@ -53,7 +57,7 @@ function createRoot({ skipMigration }: { skipMigration: boolean }) {
}
describe('starting with `migration.skip: true` when indices are up to date', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -72,7 +76,7 @@ describe('starting with `migration.skip: true` when indices are up to date', ()
});
it('starts and display the correct service status', async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {

View file

@ -7,7 +7,7 @@
*/
import { REMOVED_TYPES } from '@kbn/core-saved-objects-migration-server-internal';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { createRoot } from '@kbn/core-test-helpers-kbn-server';
// Types should NEVER be removed from this array
const previouslyRegisteredTypes = [
@ -128,7 +128,7 @@ const previouslyRegisteredTypes = [
describe('SO type registrations', () => {
it('does not remove types from registrations without updating excludeOnUpgradeQuery', async () => {
const root = kbnTestServer.createRoot({}, { oss: false });
const root = createRoot({}, { oss: false });
await root.preboot();
const setup = await root.setup();
const currentlyRegisteredTypes = setup.savedObjects

View file

@ -11,7 +11,11 @@ import fs from 'fs/promises';
import JSON5 from 'json5';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import { retryAsync } from '@kbn/core-saved-objects-migration-server-mocks';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
const logFilePath = Path.join(__dirname, 'wait_for_migration_completion.log');
@ -22,7 +26,7 @@ async function removeLogFile() {
}
describe('migration with waitForCompletion=true', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
beforeAll(async () => {
@ -41,7 +45,7 @@ describe('migration with waitForCompletion=true', () => {
});
it('waits for another instance to complete the migration', async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {
@ -120,7 +124,7 @@ describe('migration with waitForCompletion=true', () => {
});
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,

View file

@ -7,13 +7,14 @@
*/
import { migratorInstanceMock } from './migrate.test.mocks';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
describe('SavedObjects /_migrate endpoint', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
beforeEach(async () => {
root = kbnTestServer.createRoot({
root = createRoot({
migrations: { skip: true },
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
@ -29,18 +30,18 @@ describe('SavedObjects /_migrate endpoint', () => {
});
it('calls runMigrations on the migrator with rerun=true when accessed', async () => {
await kbnTestServer.request.post(root, '/internal/saved_objects/_migrate').send({}).expect(200);
await request.post(root, '/internal/saved_objects/_migrate').send({}).expect(200);
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(1);
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledWith({ rerun: true });
});
it('calls runMigrations multiple time when multiple access', async () => {
await kbnTestServer.request.post(root, '/internal/saved_objects/_migrate').send({}).expect(200);
await request.post(root, '/internal/saved_objects/_migrate').send({}).expect(200);
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(1);
await kbnTestServer.request.post(root, '/internal/saved_objects/_migrate').send({}).expect(200);
await request.post(root, '/internal/saved_objects/_migrate').send({}).expect(200);
expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(2);
});

View file

@ -7,13 +7,17 @@
*/
import { InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import * as kbnTestServer from '../../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { Root } from '@kbn/core-root-server-internal';
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
});
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
describe('SavedObjectsRepository', () => {
let root: Root;
@ -21,7 +25,7 @@ describe('SavedObjectsRepository', () => {
beforeAll(async () => {
esServer = await startES();
root = kbnTestServer.createRootWithCorePlugins({
root = createRootWithCorePlugins({
server: {
basePath: '/hello',
},

View file

@ -13,7 +13,11 @@ import type { SavedObject } from '@kbn/core-saved-objects-common';
import type { ISavedObjectsRepository } from '@kbn/core-saved-objects-api-server';
import type { InternalCoreSetup, InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import { Root } from '@kbn/core-root-server-internal';
import * as kbnTestServer from '../../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import {
declareGetRoute,
declareDeleteRoute,
@ -28,7 +32,7 @@ import {
setProxyInterrupt,
} from './repository_with_proxy_utils';
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let hapiServer: Hapi.Server;
const registerSOTypes = (setup: InternalCoreSetup) => {
@ -74,7 +78,7 @@ describe('404s from proxies', () => {
beforeAll(async () => {
setProxyInterrupt(null);
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
});
esServer = await startES();
@ -110,7 +114,7 @@ describe('404s from proxies', () => {
await hapiServer.start();
// Setup kibana configured to use proxy as ES backend
root = kbnTestServer.createRootWithCorePlugins({
root = createRootWithCorePlugins({
elasticsearch: {
hosts: [`http://${esHostname}:${proxyPort}`],
},

View file

@ -17,7 +17,11 @@ import type { SavedObjectsType } from '@kbn/core-saved-objects-server';
import { getEnvOptions } from '@kbn/config-mocks';
import type { InternalCoreSetup, InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
import { Root } from '@kbn/core-root-server-internal';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import {
createRootWithCorePlugins,
createTestServers,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version;
const logFilePath = Path.join(__dirname, 'saved_object_type_validation.log');
@ -30,7 +34,7 @@ async function removeLogFile() {
}
function createRoot() {
return kbnTestServer.createRootWithCorePlugins(
return createRootWithCorePlugins(
{
migrations: {
skip: false,
@ -122,7 +126,7 @@ const savedObjectTypes: SavedObjectsType[] = [
];
describe('validates saved object types when a schema is provided', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
let root: Root;
let coreSetup: InternalCoreSetup;
let coreStart: InternalCoreStart;
@ -131,7 +135,7 @@ describe('validates saved object types when a schema is provided', () => {
beforeAll(async () => {
await removeLogFile();
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
settings: {
es: {

View file

@ -9,10 +9,10 @@
import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import {
createTestServers,
TestElasticsearchUtils,
TestKibanaUtils,
TestUtils,
} from '../../../test_helpers/kbn_server';
type TestElasticsearchUtils,
type TestKibanaUtils,
type TestUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import { httpServerMock } from '@kbn/core-http-server-mocks';
import { createOrUpgradeSavedConfig } from '@kbn/core-ui-settings-server-internal';

View file

@ -10,15 +10,15 @@ import type supertest from 'supertest';
import type { Client } from '@elastic/elasticsearch';
import { httpServerMock } from '@kbn/core-http-server-mocks';
import type { SavedObjectsClientContract, IUiSettingsClient } from '../../..';
import {
createTestServers,
TestElasticsearchUtils,
TestKibanaUtils,
TestUtils,
HttpMethod,
getSupertest,
} from '../../../../test_helpers/kbn_server';
type TestElasticsearchUtils,
type TestKibanaUtils,
type TestUtils,
type HttpMethod,
} from '@kbn/core-test-helpers-kbn-server';
import type { SavedObjectsClientContract, IUiSettingsClient } from '../../..';
let servers: TestUtils;
let esServer: TestElasticsearchUtils;

View file

@ -7,13 +7,13 @@
*/
import { schema } from '@kbn/config-schema';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';
describe('ui settings service', () => {
describe('routes', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
beforeAll(async () => {
root = kbnTestServer.createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
});
@ -33,7 +33,7 @@ describe('ui settings service', () => {
describe('set', () => {
it('validates value', async () => {
const response = await kbnTestServer.request
const response = await request
.post(root, '/api/kibana/settings/custom')
.send({ value: 100 })
.expect(400);
@ -45,7 +45,7 @@ describe('ui settings service', () => {
});
describe('set many', () => {
it('validates value', async () => {
const response = await kbnTestServer.request
const response = await request
.post(root, '/api/kibana/settings')
.send({ changes: { custom: 100, foo: 'bar' } })
.expect(400);

View file

@ -6,7 +6,12 @@
* Side Public License, v 1.
*/
import * as kbnTestServer from './kbn_server';
import {
type TestElasticsearchUtils,
createRootWithCorePlugins,
createTestServers,
getSupertest,
} from '@kbn/core-test-helpers-kbn-server';
import { SavedObject } from '../types';
import { SavedObjectsType } from '../server';
@ -43,9 +48,9 @@ type ExportOptions = { type: string } | { objects: Array<{ id: string; type: str
export const createTestHarness = () => {
let started = false;
let stopped = false;
let esServer: kbnTestServer.TestElasticsearchUtils;
const { startES } = kbnTestServer.createTestServers({ adjustTimeout: jest.setTimeout });
const root = kbnTestServer.createRootWithCorePlugins(
let esServer: TestElasticsearchUtils;
const { startES } = createTestServers({ adjustTimeout: jest.setTimeout });
const root = createRootWithCorePlugins(
// Disable reporting due to browser install issue on CI. See https://github.com/elastic/kibana/issues/102919
{ xpack: { reporting: { enabled: false } } },
{ oss: false }
@ -61,21 +66,21 @@ export const createTestHarness = () => {
throw new Error(`SavedObjectTestHarness must be started before objects can be imported`);
if (stopped) throw new Error(`SavedObjectTestHarness cannot import objects after stopped`);
const response = await kbnTestServer
const response =
// Always use overwrite=true flag so we can isolate this harness to migrations
.getSupertest(root, 'post', '/api/saved_objects/_import?overwrite=true')
.set('Content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
'--EXAMPLE',
'Content-Disposition: form-data; name="file"; filename="export.ndjson"',
'Content-Type: application/ndjson',
'',
...objects.map((o) => JSON.stringify(o)),
'--EXAMPLE--',
].join('\r\n')
)
.expect(200);
await getSupertest(root, 'post', '/api/saved_objects/_import?overwrite=true')
.set('Content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
'--EXAMPLE',
'Content-Disposition: form-data; name="file"; filename="export.ndjson"',
'Content-Type: application/ndjson',
'',
...objects.map((o) => JSON.stringify(o)),
'--EXAMPLE--',
].join('\r\n')
)
.expect(200);
if (response.body.errors?.length > 0) {
throw new Error(
@ -93,8 +98,7 @@ export const createTestHarness = () => {
throw new Error(`SavedObjectTestHarness must be started before objects can be imported`);
if (stopped) throw new Error(`SavedObjectTestHarness cannot import objects after stopped`);
const response = await kbnTestServer
.getSupertest(root, 'post', '/api/saved_objects/_export')
const response = await getSupertest(root, 'post', '/api/saved_objects/_export')
.send({
...options,
excludeExportDetails: true,
@ -128,7 +132,7 @@ export const createTestHarness = () => {
await waitForTrue({
predicate: async () => {
const statusApi = kbnTestServer.getSupertest(root, 'get', '/api/status');
const statusApi = getSupertest(root, 'get', '/api/status');
const response = await statusApi.send();
return response.status === 200;
},

View file

@ -10,9 +10,9 @@ import { ElasticsearchClient } from '@kbn/core/server';
import { Readable } from 'stream';
import {
createTestServers,
TestElasticsearchUtils,
TestKibanaUtils,
} from '@kbn/core/test_helpers/kbn_server';
type TestElasticsearchUtils,
type TestKibanaUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { ElasticsearchBlobStorageClient, BLOB_STORAGE_SYSTEM_INDEX_NAME } from '../es';

View file

@ -10,8 +10,8 @@ import { CoreStart, ElasticsearchClient } from '@kbn/core/server';
import {
createTestServers,
createRootWithCorePlugins,
TestElasticsearchUtils,
} from '@kbn/core/test_helpers/kbn_server';
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { securityMock } from '@kbn/security-plugin/server/mocks';
import type { AuditLogger } from '@kbn/security-plugin/server';
import { Readable } from 'stream';

View file

@ -11,7 +11,7 @@ import {
createRootWithCorePlugins,
createTestServers,
request,
} from '@kbn/core/test_helpers/kbn_server';
} from '@kbn/core-test-helpers-kbn-server';
import pRetry from 'p-retry';
import { FileJSON } from '../../common';
import { getFileKindsRegistry } from '../../common/file_kinds_registry';

View file

@ -8,11 +8,11 @@
import type { Logger, ISavedObjectsRepository, SavedObject } from '@kbn/core/server';
import {
type TestElasticsearchUtils,
type TestKibanaUtils,
createTestServers,
TestElasticsearchUtils,
TestKibanaUtils,
createRootWithCorePlugins,
} from '@kbn/core/test_helpers/kbn_server';
} from '@kbn/core-test-helpers-kbn-server';
import { rollDailyData } from '../daily';
import { metricsServiceMock } from '@kbn/core/server/mocks';

View file

@ -334,6 +334,8 @@
"@kbn/core-test-helpers-deprecations-getters/*": ["packages/core/test-helpers/core-test-helpers-deprecations-getters/*"],
"@kbn/core-test-helpers-http-setup-browser": ["packages/core/test-helpers/core-test-helpers-http-setup-browser"],
"@kbn/core-test-helpers-http-setup-browser/*": ["packages/core/test-helpers/core-test-helpers-http-setup-browser/*"],
"@kbn/core-test-helpers-kbn-server": ["packages/core/test-helpers/core-test-helpers-kbn-server"],
"@kbn/core-test-helpers-kbn-server/*": ["packages/core/test-helpers/core-test-helpers-kbn-server/*"],
"@kbn/core-test-helpers-so-type-serializer": ["packages/core/test-helpers/core-test-helpers-so-type-serializer"],
"@kbn/core-test-helpers-so-type-serializer/*": ["packages/core/test-helpers/core-test-helpers-so-type-serializer/*"],
"@kbn/core-test-helpers-test-utils": ["packages/core/test-helpers/core-test-helpers-test-utils"],

View file

@ -7,7 +7,12 @@
import Path from 'path';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import {
type TestElasticsearchUtils,
type TestKibanaUtils,
createRootWithCorePlugins,
createTestServers,
} from '@kbn/core-test-helpers-kbn-server';
import { AGENT_POLICY_INDEX } from '../../common';
import type { PackagePolicySOAttributes, OutputSOAttributes } from '../../common/types';
@ -24,13 +29,13 @@ const logFilePath = Path.join(__dirname, 'logs.log');
// FLAKY: https://github.com/elastic/kibana/issues/133470
describe.skip('Fleet preconfiguration reset', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let kbnServer: kbnTestServer.TestKibanaUtils;
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
const registryUrl = useDockerRegistry();
const startServers = async (defaultKbnConfig: any = CLOUD_KIBANA_CONFIG) => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
es: {
@ -46,7 +51,7 @@ describe.skip('Fleet preconfiguration reset', () => {
await kbnServer.stop();
}
const root = kbnTestServer.createRootWithCorePlugins(
const root = createRootWithCorePlugins(
{
xpack: {
...kbnConfig.xpack,

View file

@ -7,7 +7,12 @@
import path from 'path';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import {
type TestElasticsearchUtils,
type TestKibanaUtils,
createTestServers,
createRootWithCorePlugins,
} from '@kbn/core-test-helpers-kbn-server';
import { fetchFleetUsage } from '../collectors/register';
@ -17,12 +22,12 @@ const logFilePath = path.join(__dirname, 'logs.log');
describe('fleet usage telemetry', () => {
let core: any;
let esServer: kbnTestServer.TestElasticsearchUtils;
let kbnServer: kbnTestServer.TestKibanaUtils;
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
const registryUrl = 'http://localhost';
const startServers = async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
es: {
@ -34,7 +39,7 @@ describe('fleet usage telemetry', () => {
esServer = await startES();
const startKibana = async () => {
const root = kbnTestServer.createRootWithCorePlugins(
const root = createRootWithCorePlugins(
{
xpack: {
fleet: {

View file

@ -10,7 +10,12 @@ import Path from 'path';
import { range } from 'lodash';
import type { ISavedObjectsRepository } from '@kbn/core/server';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import type { TestElasticsearchUtils, createRoot } from '@kbn/core-test-helpers-kbn-server';
import {
getSupertest,
createRootWithCorePlugins,
createTestServers,
} from '@kbn/core-test-helpers-kbn-server';
import type {
AgentPolicySOAttributes,
@ -23,13 +28,13 @@ import { useDockerRegistry } from './helpers';
const logFilePath = Path.join(__dirname, 'logs.log');
type Root = ReturnType<typeof kbnTestServer.createRoot>;
type Root = ReturnType<typeof createRoot>;
const startAndWaitForFleetSetup = async (root: Root) => {
const start = await root.start();
const isFleetSetupRunning = async () => {
const statusApi = kbnTestServer.getSupertest(root, 'get', '/api/status');
const statusApi = getSupertest(root, 'get', '/api/status');
const resp = await statusApi.send();
const fleetStatus = resp.body?.status?.plugins?.fleet;
if (fleetStatus?.meta?.error) {
@ -47,7 +52,7 @@ const startAndWaitForFleetSetup = async (root: Root) => {
};
const createAndSetupRoot = async (config?: object) => {
const root = kbnTestServer.createRootWithCorePlugins(
const root = createRootWithCorePlugins(
{
xpack: {
fleet: config,
@ -86,14 +91,14 @@ const createAndSetupRoot = async (config?: object) => {
* Verifies that multiple Kibana instances running in parallel will not create duplicate preconfiguration objects.
*/
describe('Fleet setup preconfiguration with multiple instances Kibana', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let esServer: TestElasticsearchUtils;
// let esClient: Client;
let roots: Root[] = [];
const registryUrl = useDockerRegistry();
const startServers = async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
es: {

View file

@ -6,11 +6,9 @@
*/
import { adminTestUser } from '@kbn/test';
import { getSupertest, type createRoot, type HttpMethod } from '@kbn/core-test-helpers-kbn-server';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import type { HttpMethod } from '@kbn/core/test_helpers/kbn_server';
type Root = ReturnType<typeof kbnTestServer.createRoot>;
type Root = ReturnType<typeof createRoot>;
export * from './docker_registry_helper';
@ -33,7 +31,8 @@ export const waitForFleetSetup = async (root: Root) => {
export function getSupertestWithAdminUser(root: Root, method: HttpMethod, path: string) {
const testUserCredentials = Buffer.from(`${adminTestUser.username}:${adminTestUser.password}`);
return kbnTestServer
.getSupertest(root, method, path)
.set('Authorization', `Basic ${testUserCredentials.toString('base64')}`);
return getSupertest(root, method, path).set(
'Authorization',
`Basic ${testUserCredentials.toString('base64')}`
);
}

View file

@ -7,7 +7,12 @@
import Path from 'path';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import {
type TestElasticsearchUtils,
type TestKibanaUtils,
createRootWithCorePlugins,
createTestServers,
} from '@kbn/core-test-helpers-kbn-server';
import type { AgentPolicySOAttributes } from '../types';
import { PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE } from '../../common';
@ -17,13 +22,13 @@ import { useDockerRegistry, waitForFleetSetup, getSupertestWithAdminUser } from
const logFilePath = Path.join(__dirname, 'logs.log');
describe('Fleet preconfiguration reset', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let kbnServer: kbnTestServer.TestKibanaUtils;
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
const registryUrl = useDockerRegistry();
const startServers = async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
es: {
@ -35,7 +40,7 @@ describe('Fleet preconfiguration reset', () => {
esServer = await startES();
const startKibana = async () => {
const root = kbnTestServer.createRootWithCorePlugins(
const root = createRootWithCorePlugins(
{
xpack: {
fleet: {

View file

@ -12,11 +12,17 @@ import type {
SavedObjectsClientContract,
ElasticsearchClient,
} from '@kbn/core/server';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import type { SearchTotalHits } from '@elastic/elasticsearch/lib/api/types';
import { SECURITY_EXTENSION_ID } from '@kbn/core-saved-objects-server';
import {
type TestElasticsearchUtils,
type TestKibanaUtils,
createTestServers,
createRootWithCorePlugins,
} from '@kbn/core-test-helpers-kbn-server';
import { AGENT_POLICY_SAVED_OBJECT_TYPE, FLEET_AGENT_POLICIES_SCHEMA_VERSION } from '../constants';
import { upgradeAgentPolicySchemaVersion } from '../services/setup/upgrade_agent_policy_schema_version';
import { AGENT_POLICY_INDEX } from '../../common';
@ -40,13 +46,13 @@ const fakeRequest = {
} as unknown as KibanaRequest;
describe('upgrade agent policy schema version', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let kbnServer: kbnTestServer.TestKibanaUtils;
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
const registryUrl = useDockerRegistry();
const startServers = async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
es: {
@ -58,7 +64,7 @@ describe('upgrade agent policy schema version', () => {
esServer = await startES();
const startKibana = async () => {
const root = kbnTestServer.createRootWithCorePlugins(
const root = createRootWithCorePlugins(
{
xpack: {
fleet: {

View file

@ -10,7 +10,12 @@ import Path from 'path';
import type { KibanaRequest, SavedObjectsClientContract } from '@kbn/core/server';
import { loggerMock } from '@kbn/logging-mocks';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import {
type TestElasticsearchUtils,
type TestKibanaUtils,
createRootWithCorePlugins,
createTestServers,
} from '@kbn/core-test-helpers-kbn-server';
import { SECURITY_EXTENSION_ID } from '@kbn/core-saved-objects-server';
@ -44,13 +49,13 @@ const fakeRequest = {
const PACKAGES = ['fleet_server', 'system', 'nginx', 'apache'];
describe('Uprade package install version', () => {
let esServer: kbnTestServer.TestElasticsearchUtils;
let kbnServer: kbnTestServer.TestKibanaUtils;
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
const registryUrl = useDockerRegistry();
const startServers = async () => {
const { startES } = kbnTestServer.createTestServers({
const { startES } = createTestServers({
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
es: {
@ -62,7 +67,7 @@ describe('Uprade package install version', () => {
esServer = await startES();
const startKibana = async () => {
const root = kbnTestServer.createRootWithCorePlugins(
const root = createRootWithCorePlugins(
{
xpack: {
fleet: {

View file

@ -8,10 +8,13 @@
import Boom from '@hapi/boom';
// @ts-ignore
import {
type createRoot,
request as kbnTestServerRequest,
} from '@kbn/core-test-helpers-kbn-server';
import type { CoreSetup, IBasePath, IRouter, RequestHandlerContext } from '@kbn/core/server';
import { SavedObjectsErrorHelpers } from '@kbn/core/server';
import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import type { KibanaFeature } from '@kbn/features-plugin/server';
import { featuresPluginMock } from '@kbn/features-plugin/server/mocks';
import { kibanaTestUser } from '@kbn/test';
@ -24,7 +27,7 @@ import { initSpacesOnRequestInterceptor } from './on_request_interceptor';
// FLAKY: https://github.com/elastic/kibana/issues/55953
describe.skip('onPostAuthInterceptor', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
jest.setTimeout(30000);
const headers = {
@ -39,7 +42,7 @@ describe.skip('onPostAuthInterceptor', () => {
* https://github.com/facebook/jest/issues/8379
beforeEach(async () => {
root = kbnTestServer.createRoot();
root = createRoot();
});
afterEach(async () => await root.shutdown());
@ -159,7 +162,7 @@ describe.skip('onPostAuthInterceptor', () => {
await root.start();
const response = await kbnTestServer.request.get(root, path);
const response = await kbnTestServerRequest.get(root, path);
return {
response,

View file

@ -6,6 +6,7 @@
*/
import { schema } from '@kbn/config-schema';
import { type createRoot, request } from '@kbn/core-test-helpers-kbn-server';
import type {
CoreSetup,
IBasePath,
@ -15,13 +16,12 @@ import type {
RequestHandlerContext,
} from '@kbn/core/server';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import * as kbnTestServer from '@kbn/core/test_helpers/kbn_server';
import { initSpacesOnRequestInterceptor } from './on_request_interceptor';
// FAILING: https://github.com/elastic/kibana/issues/58942
describe.skip('onRequestInterceptor', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;
/**
*
@ -29,7 +29,7 @@ describe.skip('onRequestInterceptor', () => {
* https://github.com/facebook/jest/issues/8379
beforeEach(async () => {
root = kbnTestServer.createRoot();
root = createRoot();
}, 30000);
afterEach(async () => await root.shutdown());
@ -107,7 +107,7 @@ describe.skip('onRequestInterceptor', () => {
const path = '/np_foo';
await kbnTestServer.request.get(root, path).expect(200, {
await request.get(root, path).expect(200, {
path,
basePath: '', // no base path set for route within the default space
});
@ -118,7 +118,7 @@ describe.skip('onRequestInterceptor', () => {
const path = '/s/foo-space/np_foo';
await kbnTestServer.request.get(root, path).expect(200, {
await request.get(root, path).expect(200, {
path: '/np_foo',
basePath: '/s/foo-space',
});
@ -129,7 +129,7 @@ describe.skip('onRequestInterceptor', () => {
const path = '/some/path/s/np_foo/bar';
await kbnTestServer.request.get(root, path).expect(200, {
await request.get(root, path).expect(200, {
path: '/some/path/s/np_foo/bar',
basePath: '', // no base path set for route within the default space
});
@ -140,7 +140,7 @@ describe.skip('onRequestInterceptor', () => {
const path = '/s/foo/i/love/np_spaces?queryParam=queryValue';
await kbnTestServer.request.get(root, path).expect(200, {
await request.get(root, path).expect(200, {
path: '/i/love/np_spaces',
basePath: '/s/foo',
query: {

View file

@ -3457,6 +3457,10 @@
version "0.0.0"
uid ""
"@kbn/core-test-helpers-kbn-server@link:bazel-bin/packages/core/test-helpers/core-test-helpers-kbn-server":
version "0.0.0"
uid ""
"@kbn/core-test-helpers-so-type-serializer@link:bazel-bin/packages/core/test-helpers/core-test-helpers-so-type-serializer":
version "0.0.0"
uid ""