Parameterize migration test for kibana version (#105417)

This commit is contained in:
Josh Dover 2021-07-19 19:41:01 +02:00 committed by GitHub
parent 887a149076
commit 595056060a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,12 @@ import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '../../../root'; import { Root } from '../../../root';
import JSON5 from 'json5'; import JSON5 from 'json5';
import { ElasticsearchClient } from '../../../elasticsearch'; import { ElasticsearchClient } from '../../../elasticsearch';
import { Env } from '@kbn/config';
import { REPO_ROOT } from '@kbn/utils';
import { getEnvOptions } from '@kbn/config/target/mocks';
const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version;
const targetIndex = `.kibana_${kibanaVersion}_001`;
const logFilePath = Path.join(__dirname, '7_13_unknown_types_test.log'); const logFilePath = Path.join(__dirname, '7_13_unknown_types_test.log');
async function removeLogFile() { async function removeLogFile() {
@ -76,7 +81,7 @@ describe('migration v2', () => {
unknownDocsWarningLog.message.startsWith( unknownDocsWarningLog.message.startsWith(
'[.kibana] CHECK_UNKNOWN_DOCUMENTS Upgrades will fail for 8.0+ because documents were found for unknown saved ' + '[.kibana] CHECK_UNKNOWN_DOCUMENTS Upgrades will fail for 8.0+ because documents were found for unknown saved ' +
'object types. To ensure that upgrades will succeed in the future, either re-enable plugins or delete ' + 'object types. To ensure that upgrades will succeed in the future, either re-enable plugins or delete ' +
'these documents from the ".kibana_8.0.0_001" index after the current upgrade completes.' `these documents from the "${targetIndex}" index after the current upgrade completes.`
) )
).toBeTruthy(); ).toBeTruthy();
@ -100,14 +105,15 @@ describe('migration v2', () => {
}); });
const client: ElasticsearchClient = esServer.es.getClient(); const client: ElasticsearchClient = esServer.es.getClient();
const { body: response } = await client.indices.getSettings({ index: '.kibana_8.0.0_001' }); const { body: response } = await client.indices.getSettings({
const settings = response['.kibana_8.0.0_001'] index: targetIndex,
.settings as estypes.IndicesIndexStatePrefixedSettings; });
const settings = response[targetIndex].settings as estypes.IndicesIndexStatePrefixedSettings;
expect(settings.index).not.toBeUndefined(); expect(settings.index).not.toBeUndefined();
expect(settings.index!.blocks?.write).not.toEqual('true'); expect(settings.index!.blocks?.write).not.toEqual('true');
// Ensure that documents for unknown types were preserved in target index in an unmigrated state // Ensure that documents for unknown types were preserved in target index in an unmigrated state
const spaceDocs = await fetchDocs(client, '.kibana_8.0.0_001', 'space'); const spaceDocs = await fetchDocs(client, targetIndex, 'space');
expect(spaceDocs.map((s) => s.id)).toEqual( expect(spaceDocs.map((s) => s.id)).toEqual(
expect.arrayContaining([ expect.arrayContaining([
'space:default', 'space:default',
@ -123,7 +129,7 @@ describe('migration v2', () => {
expect(d.migrationVersion.space).toEqual('6.6.0'); expect(d.migrationVersion.space).toEqual('6.6.0');
expect(d.coreMigrationVersion).toEqual('7.13.0'); expect(d.coreMigrationVersion).toEqual('7.13.0');
}); });
const fooDocs = await fetchDocs(client, '.kibana_8.0.0_001', 'foo'); const fooDocs = await fetchDocs(client, targetIndex, 'foo');
expect(fooDocs.map((f) => f.id)).toEqual( expect(fooDocs.map((f) => f.id)).toEqual(
expect.arrayContaining([ expect.arrayContaining([
'P2SQfHkBs3dBRGh--No5', 'P2SQfHkBs3dBRGh--No5',
@ -155,13 +161,13 @@ describe('migration v2', () => {
namespaceType: 'agnostic', namespaceType: 'agnostic',
migrations: { migrations: {
'6.6.0': (d) => d, '6.6.0': (d) => d,
'8.0.0': (d) => d, [kibanaVersion]: (d) => d,
}, },
}); });
await root.start(); await root.start();
const client: ElasticsearchClient = esServer.es.getClient(); const client: ElasticsearchClient = esServer.es.getClient();
const spacesDocsMigrated = await fetchDocs(client, '.kibana_8.0.0_001', 'space'); const spacesDocsMigrated = await fetchDocs(client, targetIndex, 'space');
expect(spacesDocsMigrated.map((s) => s.id)).toEqual( expect(spacesDocsMigrated.map((s) => s.id)).toEqual(
expect.arrayContaining([ expect.arrayContaining([
'space:default', 'space:default',
@ -174,12 +180,12 @@ describe('migration v2', () => {
]) ])
); );
spacesDocsMigrated.forEach((d) => { spacesDocsMigrated.forEach((d) => {
expect(d.migrationVersion.space).toEqual('8.0.0'); // should be migrated expect(d.migrationVersion.space).toEqual(kibanaVersion); // should be migrated
expect(d.coreMigrationVersion).toEqual('8.0.0'); expect(d.coreMigrationVersion).toEqual(kibanaVersion);
}); });
// Make sure unmigrated foo docs are also still there in an unmigrated state // Make sure unmigrated foo docs are also still there in an unmigrated state
const fooDocsUnmigrated = await fetchDocs(client, '.kibana_8.0.0_001', 'foo'); const fooDocsUnmigrated = await fetchDocs(client, targetIndex, 'foo');
expect(fooDocsUnmigrated.map((f) => f.id)).toEqual( expect(fooDocsUnmigrated.map((f) => f.id)).toEqual(
expect.arrayContaining([ expect.arrayContaining([
'P2SQfHkBs3dBRGh--No5', 'P2SQfHkBs3dBRGh--No5',