[pack installer] changed version checking to use semver
This commit is contained in:
parent
75598c5f45
commit
d65e7be13d
|
@ -4,7 +4,7 @@ import Logger from '../../lib/logger';
|
|||
import { join } from 'path';
|
||||
import rimraf from 'rimraf';
|
||||
import mkdirp from 'mkdirp';
|
||||
import { existingInstall, checkVersion } from '../kibana';
|
||||
import { existingInstall, assertVersion } from '../kibana';
|
||||
|
||||
describe('kibana cli', function () {
|
||||
|
||||
|
@ -24,7 +24,7 @@ describe('kibana cli', function () {
|
|||
|
||||
const logger = new Logger(settings);
|
||||
|
||||
describe('checkVersion', function () {
|
||||
describe('assertVersion', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
rimraf.sync(testWorkingPath);
|
||||
|
@ -43,7 +43,7 @@ describe('kibana cli', function () {
|
|||
const errorStub = sinon.stub();
|
||||
|
||||
try {
|
||||
checkVersion(settings);
|
||||
assertVersion(settings);
|
||||
}
|
||||
catch (err) {
|
||||
errorStub(err);
|
||||
|
@ -57,7 +57,49 @@ describe('kibana cli', function () {
|
|||
settings.plugins[0].version = '1.2.3.4';
|
||||
|
||||
try {
|
||||
checkVersion(settings);
|
||||
assertVersion(settings);
|
||||
}
|
||||
catch (err) {
|
||||
errorStub(err);
|
||||
}
|
||||
|
||||
expect(errorStub.firstCall.args[0]).to.match(/incorrect version/i);
|
||||
});
|
||||
|
||||
it('should not throw an error if plugin version matches kibana version', function () {
|
||||
const errorStub = sinon.stub();
|
||||
settings.plugins[0].version = '1.0.0';
|
||||
|
||||
try {
|
||||
assertVersion(settings);
|
||||
}
|
||||
catch (err) {
|
||||
errorStub(err);
|
||||
}
|
||||
|
||||
expect(errorStub.called).to.be(false);
|
||||
});
|
||||
|
||||
it('should ignore version info after the dash in checks on valid version', function () {
|
||||
const errorStub = sinon.stub();
|
||||
settings.plugins[0].version = '1.0.0-foo-bar-version-1.2.3';
|
||||
|
||||
try {
|
||||
assertVersion(settings);
|
||||
}
|
||||
catch (err) {
|
||||
errorStub(err);
|
||||
}
|
||||
|
||||
expect(errorStub.called).to.be(false);
|
||||
});
|
||||
|
||||
it('should ignore version info after the dash in checks on invalid version', function () {
|
||||
const errorStub = sinon.stub();
|
||||
settings.plugins[0].version = '2.0.0-foo-bar-version-1.2.3';
|
||||
|
||||
try {
|
||||
assertVersion(settings);
|
||||
}
|
||||
catch (err) {
|
||||
errorStub(err);
|
||||
|
|
|
@ -4,7 +4,7 @@ import { cleanPrevious, cleanArtifacts } from './cleanup';
|
|||
import { extract, getPackData } from './pack';
|
||||
import { sync as rimrafSync } from 'rimraf';
|
||||
import { renameSync } from 'fs';
|
||||
import { existingInstall, rebuildCache, checkVersion } from './kibana';
|
||||
import { existingInstall, rebuildCache, assertVersion } from './kibana';
|
||||
import mkdirp from 'mkdirp';
|
||||
|
||||
const mkdir = Promise.promisify(mkdirp);
|
||||
|
@ -25,7 +25,7 @@ export default async function install(settings, logger) {
|
|||
|
||||
existingInstall(settings, logger);
|
||||
|
||||
checkVersion(settings);
|
||||
assertVersion(settings);
|
||||
|
||||
renameSync(settings.workingPath, settings.plugins[0].path);
|
||||
|
||||
|
|
|
@ -2,6 +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 { statSync } from 'fs';
|
||||
|
||||
export function existingInstall(settings, logger) {
|
||||
|
@ -44,12 +45,12 @@ export async function rebuildCache(settings, logger) {
|
|||
await kbnServer.close();
|
||||
}
|
||||
|
||||
export function checkVersion(settings) {
|
||||
export function assertVersion(settings) {
|
||||
if (!settings.plugins[0].version) {
|
||||
throw new Error (`Plugin version not found. Check package.json in archive`);
|
||||
}
|
||||
|
||||
if (settings.plugins[0].version !== settings.version) {
|
||||
if (!versionSatisfies(settings.plugins[0].version, settings.version)) {
|
||||
throw new Error (`Incorrect version in plugin [${settings.plugins[0].name}]. ` +
|
||||
`Expected [${settings.version}]; found [${settings.plugins[0].version}]`);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import versionSatisfies from '../version_satisfies';
|
||||
import versionSatisfies from '../../../../utils/version_satisfies';
|
||||
import expect from 'expect.js';
|
||||
|
||||
const versionChecks = [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import _ from 'lodash';
|
||||
import esBool from './es_bool';
|
||||
import versionSatisfies from './version_satisfies';
|
||||
import versionSatisfies from '../../../utils/version_satisfies';
|
||||
import SetupError from './setup_error';
|
||||
|
||||
module.exports = function (server) {
|
||||
|
|
Loading…
Reference in a new issue