forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test tracking changes performed on all SO types migra…
…tion metadata (elastic#142306) * create empty test helper package * create extractor * create hash extraction logic * fix pkg names * actually create the test * updating README * [CI] Auto-commit changed files from 'node scripts/generate codeowners' * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * documentation draft * add more fields and update snapshot * update review doc * update review documentation * more feedback * updating snapshot Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
Showing
17 changed files
with
997 additions
and
0 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
111 changes: 111 additions & 0 deletions
111
packages/core/test-helpers/core-test-helpers-so-type-serializer/BUILD.bazel
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,111 @@ | ||
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-so-type-serializer" | ||
PKG_REQUIRE_NAME = "@kbn/core-test-helpers-so-type-serializer" | ||
|
||
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//semver", | ||
"//packages/kbn-std", | ||
] | ||
|
||
TYPES_DEPS = [ | ||
"@npm//@types/node", | ||
"@npm//@types/jest", | ||
"@npm//@types/semver", | ||
"//packages/kbn-std:npm_module_types", | ||
"//packages/core/saved-objects/core-saved-objects-common:npm_module_types", | ||
"//packages/core/saved-objects/core-saved-objects-server: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, | ||
declaration_map = 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"], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_module", | ||
deps = [":" + PKG_DIRNAME], | ||
) | ||
|
||
filegroup( | ||
name = "build", | ||
srcs = [":npm_module"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm_types( | ||
name = "npm_module_types", | ||
srcs = SRCS, | ||
deps = [":tsc_types"], | ||
package_name = PKG_REQUIRE_NAME, | ||
tsconfig = ":tsconfig", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "build_types", | ||
srcs = [":npm_module_types"], | ||
visibility = ["//visibility:public"], | ||
) |
3 changes: 3 additions & 0 deletions
3
packages/core/test-helpers/core-test-helpers-so-type-serializer/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,3 @@ | ||
# @kbn/core-test-helpers-so-type-serializer | ||
|
||
Utility package for savedObjects integration tests. |
11 changes: 11 additions & 0 deletions
11
packages/core/test-helpers/core-test-helpers-so-type-serializer/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,11 @@ | ||
/* | ||
* 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 type { SavedObjectTypeMigrationInfo } from './src/extract_migration_info'; | ||
export { extractMigrationInfo } from './src/extract_migration_info'; | ||
export { getMigrationHash } from './src/get_migration_hash'; |
13 changes: 13 additions & 0 deletions
13
packages/core/test-helpers/core-test-helpers-so-type-serializer/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-so-type-serializer'], | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/core/test-helpers/core-test-helpers-so-type-serializer/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,7 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/core-test-helpers-so-type-serializer", | ||
"owner": "@elastic/kibana-core", | ||
"runtimeDeps": [], | ||
"typeDeps": [], | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/core/test-helpers/core-test-helpers-so-type-serializer/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,8 @@ | ||
{ | ||
"name": "@kbn/core-test-helpers-so-type-serializer", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "./target_node/index.js", | ||
"author": "Kibana Core", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
161 changes: 161 additions & 0 deletions
161
...core/test-helpers/core-test-helpers-so-type-serializer/src/extract_migration_info.test.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,161 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; | ||
import { extractMigrationInfo } from './extract_migration_info'; | ||
|
||
const createType = (parts: Partial<SavedObjectsType>): SavedObjectsType => ({ | ||
name: 'test-type', | ||
hidden: false, | ||
namespaceType: 'multiple', | ||
mappings: { properties: {} }, | ||
...parts, | ||
}); | ||
|
||
const dummyMigration = jest.fn(); | ||
const dummySchema = schema.object({}); | ||
|
||
describe('extractMigrationInfo', () => { | ||
describe('simple fields', () => { | ||
it('returns the `name` from the SO type', () => { | ||
const type = createType({ name: 'my-type' }); | ||
const output = extractMigrationInfo(type); | ||
expect(output.name).toEqual('my-type'); | ||
}); | ||
|
||
it('returns the `namespaceType` from the SO type', () => { | ||
const type = createType({ namespaceType: 'multiple-isolated' }); | ||
const output = extractMigrationInfo(type); | ||
expect(output.namespaceType).toEqual('multiple-isolated'); | ||
}); | ||
|
||
it('returns the `convertToMultiNamespaceTypeVersion` from the SO type', () => { | ||
const type = createType({ convertToMultiNamespaceTypeVersion: '6.6.6' }); | ||
const output = extractMigrationInfo(type); | ||
expect(output.convertToMultiNamespaceTypeVersion).toEqual('6.6.6'); | ||
}); | ||
|
||
it('returns the `convertToAliasScript` from the SO type', () => { | ||
const type = createType({ convertToAliasScript: 'some_value' }); | ||
const output = extractMigrationInfo(type); | ||
expect(output.convertToAliasScript).toEqual('some_value'); | ||
}); | ||
|
||
it('returns true for `hasExcludeOnUpgrade` if the SO type specifies `excludeOnUpgrade`', () => { | ||
expect( | ||
extractMigrationInfo(createType({ excludeOnUpgrade: jest.fn() })).hasExcludeOnUpgrade | ||
).toEqual(true); | ||
expect( | ||
extractMigrationInfo(createType({ excludeOnUpgrade: undefined })).hasExcludeOnUpgrade | ||
).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('migrations', () => { | ||
it('returns the versions with registered migrations, sorted asc', () => { | ||
const type = createType({ | ||
migrations: { | ||
'8.3.3': dummyMigration, | ||
'7.17.7': dummyMigration, | ||
'8.0.2': dummyMigration, | ||
}, | ||
}); | ||
|
||
const output = extractMigrationInfo(type); | ||
|
||
expect(output.migrationVersions).toEqual(['7.17.7', '8.0.2', '8.3.3']); | ||
}); | ||
|
||
it('supports migration provider functions', () => { | ||
const type = createType({ | ||
migrations: () => ({ | ||
'8.3.3': dummyMigration, | ||
'7.17.7': dummyMigration, | ||
'8.0.2': dummyMigration, | ||
}), | ||
}); | ||
|
||
const output = extractMigrationInfo(type); | ||
|
||
expect(output.migrationVersions).toEqual(['7.17.7', '8.0.2', '8.3.3']); | ||
}); | ||
|
||
it('returns an empty list when migrations are not defined', () => { | ||
const type = createType({ | ||
migrations: undefined, | ||
}); | ||
|
||
const output = extractMigrationInfo(type); | ||
|
||
expect(output.migrationVersions).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('schemas', () => { | ||
it('returns the versions with registered schemas, sorted asc', () => { | ||
const type = createType({ | ||
schemas: { | ||
'8.3.2': dummySchema, | ||
'7.15.2': dummySchema, | ||
'8.1.2': dummySchema, | ||
}, | ||
}); | ||
|
||
const output = extractMigrationInfo(type); | ||
|
||
expect(output.schemaVersions).toEqual(['7.15.2', '8.1.2', '8.3.2']); | ||
}); | ||
|
||
it('supports schema provider functions', () => { | ||
const type = createType({ | ||
schemas: () => ({ | ||
'8.3.2': dummySchema, | ||
'7.15.2': dummySchema, | ||
'8.1.2': dummySchema, | ||
}), | ||
}); | ||
|
||
const output = extractMigrationInfo(type); | ||
|
||
expect(output.schemaVersions).toEqual(['7.15.2', '8.1.2', '8.3.2']); | ||
}); | ||
|
||
it('returns an empty list when schemas are not defined', () => { | ||
const type = createType({ | ||
schemas: undefined, | ||
}); | ||
|
||
const output = extractMigrationInfo(type); | ||
|
||
expect(output.schemaVersions).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('mappings', () => { | ||
it('returns a flattened version of the mappings', () => { | ||
const type = createType({ | ||
mappings: { | ||
dynamic: false, | ||
properties: { | ||
description: { type: 'text' }, | ||
hits: { type: 'integer', index: false, doc_values: false }, | ||
}, | ||
}, | ||
}); | ||
const output = extractMigrationInfo(type); | ||
expect(output.mappings).toEqual({ | ||
dynamic: false, | ||
'properties.description.type': 'text', | ||
'properties.hits.doc_values': false, | ||
'properties.hits.index': false, | ||
'properties.hits.type': 'integer', | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.