Skip to content

Commit

Permalink
Fix documentMigrator for snapshot releases (#89936)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf authored Feb 2, 2021
1 parent 7a45fc4 commit 69f4c9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 69f4c9d

Please sign in to comment.