-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-upgrade-branch
- Loading branch information
Showing
616 changed files
with
19,521 additions
and
4,157 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/core/test-helpers/core-test-helpers-model-versions/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @kbn/core-test-helpers-model-versions | ||
|
||
Package exposing utilities for model version integration testing. | ||
|
||
This package exposes a `createModelVersionTestBed` utility which allow simulating | ||
a testbed environment where we're in the cohabitation period between two versions, to test the interactions | ||
between two model versions of a set of SO types. | ||
|
||
### Limitations: | ||
|
||
Because the test bed is only creating the parts of Core required to create the two SO | ||
repositories, and because we're not loading all plugins (for proper isolation), the integration | ||
test bed has some limitations: | ||
|
||
- no extensions are enabled | ||
- no security | ||
- no encryption | ||
- no spaces | ||
- all SO types will be using the same SO index |
16 changes: 16 additions & 0 deletions
16
packages/core/test-helpers/core-test-helpers-model-versions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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 { createModelVersionTestBed } from './src/test_bed'; | ||
|
||
export type { | ||
ModelVersionTestBed, | ||
ModelVersionTestKit, | ||
ModelVersionTestkitOptions, | ||
SavedObjectTestkitDefinition, | ||
} from './src/types'; |
13 changes: 13 additions & 0 deletions
13
packages/core/test-helpers/core-test-helpers-model-versions/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-model-versions'], | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/core/test-helpers/core-test-helpers-model-versions/kibana.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/core-test-helpers-model-versions", | ||
"owner": "@elastic/kibana-core", | ||
"devOnly": true | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/core/test-helpers/core-test-helpers-model-versions/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@kbn/core-test-helpers-model-versions", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/core/test-helpers/core-test-helpers-model-versions/src/elasticsearch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { createTestServers, type TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server'; | ||
|
||
/** | ||
* Start the traditional ES cluster and return the instance. | ||
*/ | ||
export const startElasticsearch = async ({ | ||
basePath, | ||
dataArchive, | ||
timeout, | ||
}: { | ||
basePath?: string; | ||
dataArchive?: string; | ||
timeout?: number; | ||
} = {}): Promise<TestElasticsearchUtils> => { | ||
const { startES } = createTestServers({ | ||
adjustTimeout: (t: number) => jest.setTimeout(t + (timeout ?? 0)), | ||
settings: { | ||
es: { | ||
license: 'basic', | ||
basePath, | ||
dataArchive, | ||
}, | ||
}, | ||
}); | ||
return await startES(); | ||
}; |
89 changes: 89 additions & 0 deletions
89
packages/core/test-helpers/core-test-helpers-model-versions/src/test_bed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server'; | ||
import { startElasticsearch } from './elasticsearch'; | ||
import { prepareModelVersionTestKit } from './test_kit'; | ||
import type { ModelVersionTestBed } from './types'; | ||
|
||
/** | ||
* Create a {@link ModelVersionTestBed} that can be used for model version integration testing. | ||
* | ||
* @example | ||
* ```ts | ||
* describe('myIntegrationTest', () => { | ||
* const testbed = createModelVersionTestBed(); | ||
* let testkit: ModelVersionTestKit; | ||
* | ||
* beforeAll(async () => { | ||
* await testbed.startES(); | ||
* }); | ||
* | ||
* afterAll(async () => { | ||
* await testbed.stopES(); | ||
* }); | ||
* | ||
* beforeEach(async () => { | ||
* testkit = await testbed.prepareTestKit({ | ||
* savedObjectDefinitions: [{ | ||
* definition: mySoTypeDefinition, | ||
* modelVersionBefore: 1, | ||
* modelVersionAfter: 2, | ||
* }] | ||
* }) | ||
* }); | ||
* | ||
* afterEach(async () => { | ||
* if(testkit) { | ||
* await testkit.tearsDown(); | ||
* } | ||
* }); | ||
* | ||
* it('can be used to test model version cohabitation', async () => { | ||
* // last registered version is `1` | ||
* const repositoryV1 = testkit.repositoryBefore; | ||
* // last registered version is `2` | ||
* const repositoryV2 = testkit.repositoryAfter; | ||
* | ||
* // do something with the two repositories, e.g | ||
* await repositoryV1.create(someAttrs, { id }); | ||
* const v2docReadFromV1 = await repositoryV2.get('my-type', id); | ||
* expect(v2docReadFromV1.attributes).toEqual(something); | ||
* }) | ||
* }) | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
export const createModelVersionTestBed = (): ModelVersionTestBed => { | ||
let elasticsearch: TestElasticsearchUtils | undefined; | ||
|
||
const startES = async () => { | ||
if (elasticsearch) { | ||
throw new Error('Elasticsearch already started'); | ||
} | ||
elasticsearch = await startElasticsearch(); | ||
}; | ||
|
||
const stopES = async () => { | ||
if (!elasticsearch) { | ||
throw new Error('Elasticsearch not started'); | ||
} | ||
await elasticsearch.stop(); | ||
await delay(10); | ||
elasticsearch = undefined; | ||
}; | ||
|
||
return { | ||
startES, | ||
stopES, | ||
prepareTestKit: prepareModelVersionTestKit, | ||
}; | ||
}; | ||
|
||
const delay = (seconds: number) => new Promise((resolve) => setTimeout(resolve, seconds * 1000)); |
Oops, something went wrong.