From fd4074f2cd6fa528ac17acb735d7636c2d2523be Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Tue, 12 May 2020 14:30:47 -0600 Subject: [PATCH] Remove slapshot contract tests (#66277) --- test/scripts/jenkins_xpack.sh | 7 - x-pack/package.json | 1 - x-pack/scripts/jest_contract.js | 29 --- x-pack/test_utils/jest/config.contract.js | 25 --- .../example.contract.test.ts.snap | 210 ------------------ .../contract_tests/example.contract.test.ts | 97 -------- .../jest/contract_tests/global_setup.ts | 14 -- .../jest/contract_tests/global_teardown.ts | 14 -- .../sample_es_archives/example/data.json | 171 -------------- .../test_utils/jest/contract_tests/servers.ts | 132 ----------- .../contract_tests/services/es_archiver.ts | 64 ------ yarn.lock | 166 +------------- 12 files changed, 3 insertions(+), 927 deletions(-) delete mode 100644 x-pack/scripts/jest_contract.js delete mode 100644 x-pack/test_utils/jest/config.contract.js delete mode 100644 x-pack/test_utils/jest/contract_tests/__memorize_snapshots__/example.contract.test.ts.snap delete mode 100644 x-pack/test_utils/jest/contract_tests/example.contract.test.ts delete mode 100644 x-pack/test_utils/jest/contract_tests/global_setup.ts delete mode 100644 x-pack/test_utils/jest/contract_tests/global_teardown.ts delete mode 100644 x-pack/test_utils/jest/contract_tests/sample_es_archives/example/data.json delete mode 100644 x-pack/test_utils/jest/contract_tests/servers.ts delete mode 100644 x-pack/test_utils/jest/contract_tests/services/es_archiver.ts diff --git a/test/scripts/jenkins_xpack.sh b/test/scripts/jenkins_xpack.sh index c1243527de2c..395ebccb8c18 100755 --- a/test/scripts/jenkins_xpack.sh +++ b/test/scripts/jenkins_xpack.sh @@ -21,13 +21,6 @@ if [[ -z "$CODE_COVERAGE" ]] ; then echo "" echo "" - # FAILING: https://github.com/elastic/kibana/issues/44250 - # echo " -> Running jest contracts tests" - # cd "$XPACK_DIR" - # SLAPSHOT_ONLINE=true CONTRACT_ONLINE=true node scripts/jest_contract.js --ci --verbose - # echo "" - # echo "" - # echo " -> Running jest integration tests" # cd "$XPACK_DIR" # node scripts/jest_integration --ci --verbose diff --git a/x-pack/package.json b/x-pack/package.json index 3a3a0a94fa9e..46993f629c06 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -38,7 +38,6 @@ "@kbn/plugin-helpers": "9.0.2", "@kbn/test": "1.0.0", "@kbn/utility-types": "1.0.0", - "@mattapperson/slapshot": "1.4.3", "@storybook/addon-actions": "^5.2.6", "@storybook/addon-console": "^1.2.1", "@storybook/addon-knobs": "^5.2.6", diff --git a/x-pack/scripts/jest_contract.js b/x-pack/scripts/jest_contract.js deleted file mode 100644 index 3d6e7910582d..000000000000 --- a/x-pack/scripts/jest_contract.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -// # Run Jest integration tests -// -// All args will be forwarded directly to Jest, e.g. to watch tests run: -// -// node scripts/jest_contract --watch -// -// or to build code coverage: -// -// node scripts/jest_contract --coverage -// -// See all cli options in https://facebook.github.io/jest/docs/cli.html - -const resolve = require('path').resolve; -process.argv.push('--config', resolve(__dirname, '../test_utils/jest/config.contract.js')); -process.argv.push('--runInBand'); - -process.env.CONTRACT_ONLINE = 'true'; -process.env.SLAPSHOT_ONLINE = 'true'; -process.env.SLAPSHOT_RERUN_MESSAGE = - 'run "node scripts/jest_contract.js --updateSnapshot" in the x-pack directory'; - -require('../../src/setup_node_env'); -require('../../src/dev/jest/cli'); diff --git a/x-pack/test_utils/jest/config.contract.js b/x-pack/test_utils/jest/config.contract.js deleted file mode 100644 index 337763655a4d..000000000000 --- a/x-pack/test_utils/jest/config.contract.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import config from './config'; - -export default { - ...config, - testMatch: ['**/*.contract.test.{js,ts,tsx}'], - testEnvironment: 'node', - globalSetup: '/test_utils/jest/contract_tests/global_setup.ts', - globalTeardown: '/test_utils/jest/contract_tests/global_teardown.ts', - forceExit: true, - reporters: [ - 'default', - ['/../src/dev/jest/junit_reporter.js', { reportName: 'Jest Contracts Tests' }], - ], - setupFiles: [ - '/../src/dev/jest/setup/babel_polyfill.js', - '/../src/dev/jest/setup/enzyme.js', - ], - setupFilesAfterEnv: ['/../src/dev/jest/setup/after_env.integration.js'], -}; diff --git a/x-pack/test_utils/jest/contract_tests/__memorize_snapshots__/example.contract.test.ts.snap b/x-pack/test_utils/jest/contract_tests/__memorize_snapshots__/example.contract.test.ts.snap deleted file mode 100644 index 9a48e4d2889f..000000000000 --- a/x-pack/test_utils/jest/contract_tests/__memorize_snapshots__/example.contract.test.ts.snap +++ /dev/null @@ -1,210 +0,0 @@ - -exports['Example contract tests should have loaded sample data use esArchive - sample_data'] = { - "results": { - "took": 0, - "timed_out": false, - "_shards": { - "total": 1, - "successful": 1, - "skipped": 0, - "failed": 0 - }, - "hits": { - "total": { - "value": 4, - "relation": "eq" - }, - "max_score": 0.9102117, - "hits": [ - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:qux", - "_score": 0.9102117, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "1.2.3.4", - "host_name": "foo.bar.com", - "id": "qux", - "name": "qux_filebeat", - "type": "filebeat" - }, - "type": "beat" - } - }, - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:baz", - "_score": 0.9102117, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "22.33.11.44", - "host_name": "baz.bar.com", - "id": "baz", - "name": "baz_metricbeat", - "type": "metricbeat" - }, - "type": "beat" - } - }, - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:foo", - "_score": 0.9102117, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "1.2.3.4", - "host_name": "foo.bar.com", - "id": "foo", - "name": "foo_metricbeat", - "tags": [ - "production", - "qa" - ], - "type": "metricbeat", - "verified_on": "2018-05-15T16:25:38.924Z" - }, - "type": "beat" - } - }, - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:bar", - "_score": 0.9102117, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "11.22.33.44", - "host_name": "foo.com", - "id": "bar", - "name": "bar_filebeat", - "type": "filebeat" - }, - "type": "beat" - } - } - ] - } - } -} - -exports['Example contract tests should run online or offline - example_test_snapshot'] = { - "results": { - "serverExists": true - } -} - -exports['Example contract tests should run online or offline - example_test_snapshot'] = { - "results": { - "serverExists": true - } -} - -exports['Example contract tests should have loaded sample data use esArchive - sample_data'] = { - "results": { - "took": 2, - "timed_out": false, - "_shards": { - "total": 1, - "successful": 1, - "skipped": 0, - "failed": 0 - }, - "hits": { - "total": { - "value": 4, - "relation": "eq" - }, - "max_score": 0.90445626, - "hits": [ - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:qux", - "_score": 0.90445626, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "1.2.3.4", - "host_name": "foo.bar.com", - "id": "qux", - "name": "qux_filebeat", - "type": "filebeat" - }, - "type": "beat" - } - }, - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:baz", - "_score": 0.90445626, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "22.33.11.44", - "host_name": "baz.bar.com", - "id": "baz", - "name": "baz_metricbeat", - "type": "metricbeat" - }, - "type": "beat" - } - }, - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:foo", - "_score": 0.90445626, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "1.2.3.4", - "host_name": "foo.bar.com", - "id": "foo", - "name": "foo_metricbeat", - "tags": [ - "production", - "qa" - ], - "type": "metricbeat", - "verified_on": "2018-05-15T16:25:38.924Z" - }, - "type": "beat" - } - }, - { - "_index": ".management-beats", - "_type": "_doc", - "_id": "beat:bar", - "_score": 0.90445626, - "_source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "11.22.33.44", - "host_name": "foo.com", - "id": "bar", - "name": "bar_filebeat", - "type": "filebeat" - }, - "type": "beat" - } - } - ] - } - } -} diff --git a/x-pack/test_utils/jest/contract_tests/example.contract.test.ts b/x-pack/test_utils/jest/contract_tests/example.contract.test.ts deleted file mode 100644 index 642a4f2d0164..000000000000 --- a/x-pack/test_utils/jest/contract_tests/example.contract.test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import Slapshot from '@mattapperson/slapshot'; - -// import { createKibanaServer } from './servers'; -// import { getEsArchiver } from './services/es_archiver'; -// import { EsArchiver } from 'src/es_archiver'; -// import * as path from 'path'; -import * as legacyElasticsearch from 'elasticsearch'; - -// const { callWhenOnline, memorize } = Slapshot; -const { memorize } = Slapshot; - -let servers: { kbnServer: any; shutdown: () => void }; -// let esArchiver: EsArchiver; - -// FLAKY: https://github.com/elastic/kibana/issues/44250 -describe.skip('Example contract tests', () => { - /** - * - * commented out due to hooks being called regardless of skip - * https://github.com/facebook/jest/issues/8379 - - beforeAll(async () => { - await callWhenOnline(async () => { - servers = await createKibanaServer(); - esArchiver = getEsArchiver({ - kibanaUrl: servers.kbnServer.info.uri, - dir: path.resolve(__dirname, 'sample_es_archives'), - }); - }); - }); - - afterAll(async () => { - if (servers) { - await servers.shutdown(); - } - }); - - beforeEach(async () => await callWhenOnline(() => esArchiver.load('example'))); - afterEach(async () => await callWhenOnline(() => esArchiver.unload('example'))); - - */ - - it('should run online or offline', async () => { - const res = await memorize('example_test_snapshot', async () => { - return { serverExists: !!servers.kbnServer }; - }); - - expect(res).toBeDefined(); - expect(res.serverExists).toBe(true); - }); - - it('should have loaded sample data use esArchive', async () => { - const dataInES: any = await memorize('sample_data', () => { - // To keep things simple in this example, getting the connection infor the the JEST contract test ES server - const esConfig = JSON.parse(process.env.__JEST__ESServer || ''); - const client = new legacyElasticsearch.Client({ - hosts: esConfig.hosts, - httpAuth: esConfig.username ? `${esConfig.username}:${esConfig.password}` : undefined, - }); - - return new Promise((resolve, reject) => { - client.search( - { - index: '.management-beats', - size: 10000, - ignore: [404], - body: { - query: { - bool: { - must: { - term: { - type: 'beat', - }, - }, - }, - }, - }, - }, - (err, data) => { - if (err) reject(err); - - resolve(data); - } - ); - }); - }); - - expect(dataInES).toBeDefined(); - expect(dataInES.hits.hits.length).toEqual(4); - }); -}); diff --git a/x-pack/test_utils/jest/contract_tests/global_setup.ts b/x-pack/test_utils/jest/contract_tests/global_setup.ts deleted file mode 100644 index 3795e10d995b..000000000000 --- a/x-pack/test_utils/jest/contract_tests/global_setup.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { _createSharedServer } from './servers'; - -// eslint-disable-next-line import/no-default-export -export default async function globalSetup() { - if (process.env.CONTRACT_ONLINE === 'true') { - await _createSharedServer(); - } -} diff --git a/x-pack/test_utils/jest/contract_tests/global_teardown.ts b/x-pack/test_utils/jest/contract_tests/global_teardown.ts deleted file mode 100644 index 010e14f8702f..000000000000 --- a/x-pack/test_utils/jest/contract_tests/global_teardown.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { _stopSharedServer } from './servers'; - -// eslint-disable-next-line import/no-default-export -export default async function globalTeardown() { - if (process.env.CONTRACT_ONLINE === 'true') { - await _stopSharedServer(); - } -} diff --git a/x-pack/test_utils/jest/contract_tests/sample_es_archives/example/data.json b/x-pack/test_utils/jest/contract_tests/sample_es_archives/example/data.json deleted file mode 100644 index c2c4aba83a1c..000000000000 --- a/x-pack/test_utils/jest/contract_tests/sample_es_archives/example/data.json +++ /dev/null @@ -1,171 +0,0 @@ -{ - "value": { - "id": "beat:qux", - "index": ".management-beats", - "source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "1.2.3.4", - "host_name": "foo.bar.com", - "id": "qux", - "name": "qux_filebeat", - "type": "filebeat" - }, - "type": "beat" - } - } -} - -{ - "value": { - "id": "beat:baz", - "index": ".management-beats", - "source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "22.33.11.44", - "host_name": "baz.bar.com", - "id": "baz", - "name": "baz_metricbeat", - "type": "metricbeat" - }, - "type": "beat" - } - } -} - -{ - "value": { - "id": "beat:foo", - "index": ".management-beats", - "source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "1.2.3.4", - "host_name": "foo.bar.com", - "id": "foo", - "name": "foo_metricbeat", - "tags": [ - "production", - "qa" - ], - "type": "metricbeat", - "verified_on": "2018-05-15T16:25:38.924Z" - }, - "type": "beat" - } - } -} - -{ - "value": { - "id": "beat:bar", - "index": ".management-beats", - "source": { - "beat": { - "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI", - "active": true, - "host_ip": "11.22.33.44", - "host_name": "foo.com", - "id": "bar", - "name": "bar_filebeat", - "type": "filebeat" - }, - "type": "beat" - } - } -} - -{ - "value": { - "id": "tag:production", - "index": ".management-beats", - "source": { - "tag": { - "color": "blue" - }, - "type": "tag" - } - } -} - -{ - "value": { - "id": "tag:development", - "index": ".management-beats", - "source": { - "tag": { - "color": "red" - }, - "type": "tag" - } - } -} - -{ - "value": { - "id": "tag:qa", - "index": ".management-beats", - "source": { - "tag": { - "color": "green" - }, - "type": "tag" - } - } -} - -{ - "value": { - "id": "configuration_block:SDfsdfIBdsfsf50zbta", - "index": ".management-beats", - "source": { - "configuration_block": { - "config": "{ \"username\": \"some-username\", \"hosts\": [\"localhost:11211\"] }", - "description": "some description", - "last_updated": "2018-05-15T16:25:38.924Z", - "tag": "production", - "type": "output" - }, - "type": "configuration_block" - }, - "type": "_doc" - } -} - -{ - "value": { - "id": "configuration_block:W0tpsmIBdsfsf50zbta", - "index": ".management-beats", - "source": { - "configuration_block": { - "config": "{ \"module\": \"memcached\", \"hosts\": [\"localhost:11211\"] }", - "last_updated": "2018-05-15T16:25:38.924Z", - "tag": "production", - "type": "metricbeat.modules" - }, - "type": "configuration_block" - }, - "type": "_doc" - } -} - -{ - "value": { - "id": "configuration_block:W0tpsmIBdwcYyG50zbta", - "index": ".management-beats", - "source": { - "configuration_block": { - "config": "{\"module\": \"memcached\", \"node.namespace\": \"node\", \"hosts\": [\"localhost:4949\"] }", - "last_updated": "2018-05-15T16:25:38.924Z", - "tag": "qa", - "type": "metricbeat.modules" - }, - "type": "configuration_block" - }, - "type": "_doc" - } -} \ No newline at end of file diff --git a/x-pack/test_utils/jest/contract_tests/servers.ts b/x-pack/test_utils/jest/contract_tests/servers.ts deleted file mode 100644 index 415603b3adb7..000000000000 --- a/x-pack/test_utils/jest/contract_tests/servers.ts +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import url from 'url'; -import { resolve } from 'path'; -import * as kbnTestServer from '../../../../src/test_utils/kbn_server'; -import { TestKbnServerConfig } from '../../kbn_server_config'; - -const PLUGIN_PATHS = resolve(__dirname, '../../../'); - -interface ESServerConfig { - hosts: string[]; - username: string; - password: string; -} - -type ESServer = { - stop: () => void; -} & ESServerConfig; - -let ESServer: ESServer; - -function _parseESConnectionString(connectionString: string) { - const uri = (url.parse(connectionString) as unknown) as url.URL; - - return { - hosts: [connectionString], - username: uri.username || (uri as any).auth.split(':')[0], - password: uri.password || (uri as any).auth.split(':')[1], - }; -} - -/** - * Set a global variable during global setup that can be safely acceded while running tests. - * See https://github.com/facebook/jest/issues/7184 - * @param serverConfig - */ -function _setJestSafeGlobalServerConfig(serverConfig: ESServerConfig) { - process.env.__JEST__ESServer = JSON.stringify(serverConfig); -} - -/** - * Get previously set global variable - */ -function _getJestSafeGlobalServerConfig(): ESServerConfig | undefined { - if (process.env.__JEST__ESServer) { - return JSON.parse(process.env.__JEST__ESServer); - } -} - -/** - * Create a new shared ES server, - * this function should not be used outside of jest globalSetup - */ -export async function _createSharedServer() { - if (process.env.ES_SERVER_URL) { - _setJestSafeGlobalServerConfig(_parseESConnectionString(process.env.ES_SERVER_URL)); - return; - } - - const servers = await kbnTestServer.createTestServers({ - // adjustTimeout function is required by createTestServers fn - adjustTimeout: (t: number) => {}, - settings: { - ...TestKbnServerConfig, - es: { - ...TestKbnServerConfig.es, - esArgs: ['xpack.security.authc.api_key.enabled=true'], - }, - }, - }); - ESServer = await servers.startES(); - const { hosts, username, password } = ESServer; - - // Use process.env here as globals are set by jest testEnvironment - _setJestSafeGlobalServerConfig({ - hosts, - username, - password, - }); -} - -/** - * Stop a shared ES server, - * this function should not be used outside of jest globalTeardown - */ -export async function _stopSharedServer() { - if (ESServer) { - await ESServer.stop(); - } -} - -export function getSharedESServer(): ESServerConfig { - const esConfig = _getJestSafeGlobalServerConfig(); - if (!esConfig) { - throw new Error('Enable to get shared ES Server'); - } - return esConfig; -} - -/** - * Create a kibana server using a shared elasticsearch instance - */ -export async function createKibanaServer(xpackOption = {}) { - if (jest && jest.setTimeout) { - // Allow kibana to start - jest.setTimeout(240000); - } - - const root = kbnTestServer.createRootWithCorePlugins( - { - elasticsearch: { ...getSharedESServer() }, - plugins: { paths: [PLUGIN_PATHS] }, - xpack: xpackOption, - }, - { - oss: false, - } - ); - await root.setup(); - await root.start(); - const { server } = (root as any).server.legacy.kbnServer; - - return { - shutdown: async () => await root.shutdown(), - kbnServer: server, - root, - }; -} diff --git a/x-pack/test_utils/jest/contract_tests/services/es_archiver.ts b/x-pack/test_utils/jest/contract_tests/services/es_archiver.ts deleted file mode 100644 index ed18b9be5806..000000000000 --- a/x-pack/test_utils/jest/contract_tests/services/es_archiver.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import * as legacyElasticsearch from 'elasticsearch'; -import { ToolingLog } from '@kbn/dev-utils'; -import { resolve } from 'path'; -import * as fs from 'fs'; -import { EsArchiver } from '../../../../../src/es_archiver/es_archiver'; - -interface ESServerConfig { - hosts: string[]; - username: string; - password: string; -} - -export const getEsArchiver = (options: { - kibanaUrl: string; - logLevel?: 'silent' | 'error' | 'warning' | 'info' | 'debug' | 'verbose'; - dir: string; -}) => { - let esConfig: ESServerConfig | undefined; - if (process.env.__JEST__ESServer) { - esConfig = JSON.parse(process.env.__JEST__ESServer); - } - - if (!esConfig) { - throw new Error( - 'getEsArchiver was called before ES was started or else Jest contract tests are not configured correctly.' - ); - } - - const log = new ToolingLog({ - level: options.logLevel || 'info', - writeTo: process.stdout, - }); - - const client = new legacyElasticsearch.Client({ - hosts: esConfig.hosts, - httpAuth: esConfig.username ? `${esConfig.username}:${esConfig.password}` : undefined, - log: options.logLevel, - }); - - if (!fs.existsSync(resolve(options.dir))) { - throw new Error( - `getEsArchiver expects the dir option to be a path that exists on the local file system, ${resolve( - options.dir - )} does not exist` - ); - } - - const esArchiver = new EsArchiver({ - log, - client, - dataDir: resolve(options.dir), - kibanaUrl: esConfig.username - ? `http://${esConfig.username}:${esConfig.password}@${options.kibanaUrl.split('://')[1]}` - : options.kibanaUrl, - }); - - return esArchiver; -}; diff --git a/yarn.lock b/yarn.lock index 8b16bac98e89..d20dff92a086 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2211,18 +2211,6 @@ resolved "https://registry.yarnpkg.com/@mapbox/whoots-js/-/whoots-js-3.1.0.tgz#497c67a1cef50d1a2459ba60f315e448d2ad87fe" integrity sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q== -"@mattapperson/slapshot@1.4.3": - version "1.4.3" - resolved "https://registry.yarnpkg.com/@mattapperson/slapshot/-/slapshot-1.4.3.tgz#f5b81b297a3708f43f7d9242b46b37c60c1dd9ed" - integrity sha512-5BgwWHAzpethrotEFErzYtWhWyZSq6y+Yek3wzgOquCIqH+/2QoCQT3ru2ina+oIqdtSp3+4BDUMMkCKIa2uhg== - dependencies: - caller-callsite "^4.0.0" - get-caller-file "^2.0.5" - globby "^10.0.0" - parent-module "^2.0.0" - utils-error-reviver "^1.0.0" - utils-error-to-json "^1.0.0" - "@microsoft/api-documenter@7.7.2": version "7.7.2" resolved "https://registry.yarnpkg.com/@microsoft/api-documenter/-/api-documenter-7.7.2.tgz#b6897f052ad447d6bb74f806287e8846c64691da" @@ -8379,13 +8367,6 @@ caller-callsite@^2.0.0: dependencies: callsites "^2.0.0" -caller-callsite@^4.0.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/caller-callsite/-/caller-callsite-4.1.0.tgz#3e33cb1d910e7b09332d59a3503b9af7462f7295" - integrity sha512-99nnnGlJexTc41xwQTr+mWl15OI5PPczUJzM4YRE7QjkefMKCXGa5gfQjCOuVrD+1TjI/fevIDHg2nz3iYN5Ig== - dependencies: - callsites "^3.1.0" - caller-path@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f" @@ -8420,11 +8401,6 @@ callsites@^3.0.0: resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.0.0.tgz#fb7eb569b72ad7a45812f93fd9430a3e410b3dd3" integrity sha512-tWnkwu9YEq2uzlBDI4RcLn8jrFvF9AOi8PxDNU3hZZjJcjkcRAq3vCI+vZcg1SuxISDYe86k9VZFwAxDiJGoAw== -callsites@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" - integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== - camel-case@3.0.x, camel-case@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-3.0.0.tgz#ca3c3688a4e9cf3a4cda777dc4dcbc713249cf73" @@ -9717,16 +9693,6 @@ console-log-level@^1.4.1: resolved "https://registry.yarnpkg.com/console-log-level/-/console-log-level-1.4.1.tgz#9c5a6bb9ef1ef65b05aba83028b0ff894cdf630a" integrity sha512-VZzbIORbP+PPcN/gg3DXClTLPLg5Slwd5fL2MIc+o1qZ4BXBvWyc6QxPk6T/Mkr6IVjRpoAGf32XxP3ZWMVRcQ== -const-max-uint32@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/const-max-uint32/-/const-max-uint32-1.0.2.tgz#f009bb6230e678ed874dd2d6a9cd9e3cbfabb676" - integrity sha1-8Am7YjDmeO2HTdLWqc2ePL+rtnY= - -const-pinf-float64@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/const-pinf-float64/-/const-pinf-float64-1.0.0.tgz#f6efb0d79f9c0986d3e79f2923abf9b70b63d726" - integrity sha1-9u+w15+cCYbT558pI6v5twtj1yY= - constant-case@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/constant-case/-/constant-case-2.0.0.tgz#4175764d389d3fa9c8ecd29186ed6005243b6a46" @@ -14486,7 +14452,7 @@ get-caller-file@^1.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w== -get-caller-file@^2.0.1, get-caller-file@^2.0.5: +get-caller-file@^2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== @@ -14899,7 +14865,7 @@ globby@8.0.2: pify "^3.0.0" slash "^1.0.0" -globby@^10.0.0, globby@^10.0.1: +globby@^10.0.1: version "10.0.1" resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22" integrity sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A== @@ -21924,7 +21890,7 @@ object-is@^1.0.1, object-is@^1.0.2: resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.0.2.tgz#6b80eb84fe451498f65007982f035a5b445edec4" integrity sha512-Epah+btZd5wrrfjkJZq1AOB9O6OxUQto45hzFd7lXGrpHPGE0W1k+426yrZV+k6NJOzLNNW/nVsmZdIWsAqoOQ== -object-keys@^1.0.11, object-keys@^1.0.12, object-keys@^1.0.6, object-keys@^1.0.9, object-keys@^1.1.1: +object-keys@^1.0.11, object-keys@^1.0.12, object-keys@^1.0.6, object-keys@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== @@ -22620,13 +22586,6 @@ parent-module@^1.0.0: dependencies: callsites "^3.0.0" -parent-module@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-2.0.0.tgz#fa71f88ff1a50c27e15d8ff74e0e3a9523bf8708" - integrity sha512-uo0Z9JJeWzv8BG+tRcapBKNJ0dro9cLyczGzulS6EfeyAdeC9sbojtW6XwvYxJkEne9En+J2XEl4zyglVeIwFg== - dependencies: - callsites "^3.1.0" - parse-asn1@^5.0.0: version "5.1.0" resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.0.tgz#37c4f9b7ed3ab65c74817b5f2480937fbf97c712" @@ -25555,11 +25514,6 @@ regex-parser@2.2.10: resolved "https://registry.yarnpkg.com/regex-parser/-/regex-parser-2.2.10.tgz#9e66a8f73d89a107616e63b39d4deddfee912b37" integrity sha512-8t6074A68gHfU8Neftl0Le6KTDwfGAj7IyjPIMSfikI2wJUTHDMaIq42bUsfVnj8mhx0R+45rdUXHGpN164avA== -regex-regex@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/regex-regex/-/regex-regex-1.0.0.tgz#9048a1eaeb870f4d480dabc76fc42cdcc0bc3a72" - integrity sha1-kEih6uuHD01IDavHb8Qs3MC8OnI= - regexp.prototype.flags@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.2.0.tgz#6b30724e306a27833eeb171b66ac8890ba37e41c" @@ -30050,11 +30004,6 @@ type-is@~1.6.17, type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -type-name@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/type-name/-/type-name-2.0.2.tgz#efe7d4123d8ac52afff7f40c7e4dec5266008fb4" - integrity sha1-7+fUEj2KxSr/9/QMfk3sUmYAj7Q= - typechecker@^4.3.0: version "4.5.0" resolved "https://registry.yarnpkg.com/typechecker/-/typechecker-4.5.0.tgz#c382920097812364bbaf4595b0ab6588244117a6" @@ -30759,66 +30708,11 @@ utility-types@^3.10.0: resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.10.0.tgz#ea4148f9a741015f05ed74fd615e1d20e6bed82b" integrity sha512-O11mqxmi7wMKCo6HKFt5AhO4BwY3VV68YU07tgxfz8zJTIxr4BpsezN49Ffwy9j3ZpwwJp4fkRwjRzq3uWE6Rg== -utils-copy-error@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/utils-copy-error/-/utils-copy-error-1.0.1.tgz#791de393c0f09890afd59f3cbea635f079a94fa5" - integrity sha1-eR3jk8DwmJCv1Z88vqY18HmpT6U= - dependencies: - object-keys "^1.0.9" - utils-copy "^1.1.0" - -utils-copy@^1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/utils-copy/-/utils-copy-1.1.1.tgz#6e2b97982aa8cd73e1182a3e6f8bec3c0f4058a7" - integrity sha1-biuXmCqozXPhGCo+b4vsPA9AWKc= - dependencies: - const-pinf-float64 "^1.0.0" - object-keys "^1.0.9" - type-name "^2.0.0" - utils-copy-error "^1.0.0" - utils-indexof "^1.0.0" - utils-regex-from-string "^1.0.0" - validate.io-array "^1.0.3" - validate.io-buffer "^1.0.1" - validate.io-nonnegative-integer "^1.0.0" - -utils-error-reviver@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/utils-error-reviver/-/utils-error-reviver-1.0.0.tgz#152d4b34e5a42c123b2da50450bd54de85ec25cf" - integrity sha1-FS1LNOWkLBI7LaUEUL1U3oXsJc8= - dependencies: - object-keys "^1.0.9" - validate.io-string-primitive "^1.0.0" - -utils-error-to-json@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/utils-error-to-json/-/utils-error-to-json-1.0.0.tgz#61e4a7ba8567e3ce7ac2f305cd1948b2a874f300" - integrity sha1-YeSnuoVn4856wvMFzRlIsqh08wA= - dependencies: - object-keys "^1.0.9" - utils-copy "^1.1.0" - -utils-indexof@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/utils-indexof/-/utils-indexof-1.0.0.tgz#20feabf09ef1018b523643e8380e7bc83ec61b5c" - integrity sha1-IP6r8J7xAYtSNkPoOA57yD7GG1w= - dependencies: - validate.io-array-like "^1.0.1" - validate.io-integer-primitive "^1.0.0" - utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= -utils-regex-from-string@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/utils-regex-from-string/-/utils-regex-from-string-1.0.0.tgz#fe1a2909f8de0ff0d5182c80fbc654d6a687d189" - integrity sha1-/hopCfjeD/DVGCyA+8ZU1qaH0Yk= - dependencies: - regex-regex "^1.0.0" - validate.io-string-primitive "^1.0.0" - uuid@3.3.2, uuid@^3.0.1, uuid@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" @@ -30884,60 +30778,6 @@ validate-npm-package-name@2.2.2: dependencies: builtins "0.0.7" -validate.io-array-like@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/validate.io-array-like/-/validate.io-array-like-1.0.2.tgz#7af9f7eb7b51715beb2215668ec5cce54faddb5a" - integrity sha1-evn363tRcVvrIhVmjsXM5U+t21o= - dependencies: - const-max-uint32 "^1.0.2" - validate.io-integer-primitive "^1.0.0" - -validate.io-array@^1.0.3: - version "1.0.6" - resolved "https://registry.yarnpkg.com/validate.io-array/-/validate.io-array-1.0.6.tgz#5b5a2cafd8f8b85abb2f886ba153f2d93a27774d" - integrity sha1-W1osr9j4uFq7L4hroVPy2Tond00= - -validate.io-buffer@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/validate.io-buffer/-/validate.io-buffer-1.0.2.tgz#852d6734021914d5d13afc32531761e3720ed44e" - integrity sha1-hS1nNAIZFNXROvwyUxdh43IO1E4= - -validate.io-integer-primitive@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/validate.io-integer-primitive/-/validate.io-integer-primitive-1.0.0.tgz#a9aa010355fe8681c0fea6c1a74ad2419cadddc6" - integrity sha1-qaoBA1X+hoHA/qbBp0rSQZyt3cY= - dependencies: - validate.io-number-primitive "^1.0.0" - -validate.io-integer@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/validate.io-integer/-/validate.io-integer-1.0.5.tgz#168496480b95be2247ec443f2233de4f89878068" - integrity sha1-FoSWSAuVviJH7EQ/IjPeT4mHgGg= - dependencies: - validate.io-number "^1.0.3" - -validate.io-nonnegative-integer@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/validate.io-nonnegative-integer/-/validate.io-nonnegative-integer-1.0.0.tgz#8069243a08c5f98e95413c929dfd7b18f3f6f29f" - integrity sha1-gGkkOgjF+Y6VQTySnf17GPP28p8= - dependencies: - validate.io-integer "^1.0.5" - -validate.io-number-primitive@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/validate.io-number-primitive/-/validate.io-number-primitive-1.0.0.tgz#d2e01f202989369dcf1155449564203afe584e55" - integrity sha1-0uAfICmJNp3PEVVElWQgOv5YTlU= - -validate.io-number@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/validate.io-number/-/validate.io-number-1.0.3.tgz#f63ffeda248bf28a67a8d48e0e3b461a1665baf8" - integrity sha1-9j/+2iSL8opnqNSODjtGGhZluvg= - -validate.io-string-primitive@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/validate.io-string-primitive/-/validate.io-string-primitive-1.0.1.tgz#b8135b9fb1372bde02fdd53ad1d0ccd6de798fee" - integrity sha1-uBNbn7E3K94C/dU60dDM1t55j+4= - validator@^10.11.0: version "10.11.0" resolved "https://registry.yarnpkg.com/validator/-/validator-10.11.0.tgz#003108ea6e9a9874d31ccc9e5006856ccd76b228"