[pack installer] fixed version checking
This commit is contained in:
parent
f24c3b7d32
commit
f701df528f
|
@ -39,6 +39,26 @@ describe('kibana cli', function () {
|
|||
rimraf.sync(testWorkingPath);
|
||||
});
|
||||
|
||||
it('should succeed with exact match', function () {
|
||||
const settings = {
|
||||
workingPath: testWorkingPath,
|
||||
tempArchiveFile: tempArchiveFilePath,
|
||||
plugin: 'test-plugin',
|
||||
version: '5.0.0-snapshot',
|
||||
plugins: [ { name: 'foo', path: join(testWorkingPath, 'foo'), version: '5.0.0-snapshot' } ]
|
||||
};
|
||||
const errorStub = sinon.stub();
|
||||
|
||||
try {
|
||||
assertVersion(settings);
|
||||
}
|
||||
catch (err) {
|
||||
errorStub(err);
|
||||
}
|
||||
|
||||
expect(errorStub.called).to.be(false);
|
||||
});
|
||||
|
||||
it('should throw an error if plugin does contain a version.', function () {
|
||||
const errorStub = sinon.stub();
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import _ from 'lodash';
|
|||
import fromRoot from '../../utils/from_root';
|
||||
import KbnServer from '../../server/kbn_server';
|
||||
import readYamlConfig from '../../cli/serve/read_yaml_config';
|
||||
import versionSatisfies from '../../utils/version_satisfies';
|
||||
import { versionSatisfies, cleanVersion } from './version';
|
||||
import { statSync } from 'fs';
|
||||
|
||||
export function existingInstall(settings, logger) {
|
||||
|
@ -50,8 +50,10 @@ export function assertVersion(settings) {
|
|||
throw new Error (`Plugin version not found. Check package.json in archive`);
|
||||
}
|
||||
|
||||
if (!versionSatisfies(settings.plugins[0].version, settings.version)) {
|
||||
const actual = cleanVersion(settings.plugins[0].version);
|
||||
const expected = cleanVersion(settings.version);
|
||||
if (!versionSatisfies(actual, expected)) {
|
||||
throw new Error (`Incorrect version in plugin [${settings.plugins[0].name}]. ` +
|
||||
`Expected [${settings.version}]; found [${settings.plugins[0].version}]`);
|
||||
`Expected [${expected}]; found [${actual}]`);
|
||||
}
|
||||
}
|
||||
|
|
15
src/cli_plugin/install/version.js
Normal file
15
src/cli_plugin/install/version.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import semver from 'semver';
|
||||
|
||||
export function versionSatisfies(cleanActual, cleanExpected) {
|
||||
try {
|
||||
return (cleanActual === cleanExpected);
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function cleanVersion(version) {
|
||||
const match = version.match(/\d+\.\d+\.\d+/);
|
||||
if (!match) return version;
|
||||
return match[0];
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import versionSatisfies from '../../../../utils/version_satisfies';
|
||||
import versionSatisfies from '../version_satisfies';
|
||||
import expect from 'expect.js';
|
||||
|
||||
const versionChecks = [
|
||||
|
|
Loading…
Reference in a new issue