Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentMigrator for snapshot releases #89936

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import { loggingSystemMock } from '../../../logging/logging_system.mock';
import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import { SavedObjectsType } from '../../types';
import { errors as esErrors } from '@elastic/elasticsearch';
import { DocumentMigrator } from '../core/document_migrator';
jest.mock('../core/document_migrator', () => {
return {
// Create a mock for spying on the constructor
DocumentMigrator: jest.fn().mockImplementation((...args) => {
const { DocumentMigrator: RealDocMigrator } = jest.requireActual('../core/document_migrator');
return new RealDocMigrator(args[0]);
}),
};
});

const createRegistry = (types: Array<Partial<SavedObjectsType>>) => {
const registry = new SavedObjectTypeRegistry();
Expand All @@ -31,12 +41,16 @@ const createRegistry = (types: Array<Partial<SavedObjectsType>>) => {
};

describe('KibanaMigrator', () => {
beforeEach(() => {
(DocumentMigrator as jest.Mock).mockClear();
});
describe('constructor', () => {
it('coerces the current Kibana version if it has a hyphen', () => {
const options = mockOptions();
options.kibanaVersion = '3.2.1-SNAPSHOT';
const migrator = new KibanaMigrator(options);
expect(migrator.kibanaVersion).toEqual('3.2.1');
expect((DocumentMigrator as jest.Mock).mock.calls[0][0].kibanaVersion).toEqual('3.2.1');
});
});
describe('getActiveMappings', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class KibanaMigrator {
this.log = logger;
this.kibanaVersion = kibanaVersion.split('-')[0]; // coerce a semver-like string (x.y.z-SNAPSHOT) or prerelease version (x.y.z-alpha) to a regular semver (x.y.z);
this.documentMigrator = new DocumentMigrator({
kibanaVersion,
kibanaVersion: this.kibanaVersion,
typeRegistry,
log: this.log,
});
Expand Down