Skip to content

Commit

Permalink
Merge pull request #8222 from BigFunger/plugin-installer-kibana-version
Browse files Browse the repository at this point in the history
Adds concept of kibanaVersion to plugin installer
  • Loading branch information
BigFunger authored Sep 12, 2016
2 parents c25ac3c + 29f58a1 commit 90ad531
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 29 deletions.
22 changes: 11 additions & 11 deletions src/cli_plugin/install/__tests__/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('kibana cli', function () {
tempArchiveFile: tempArchiveFilePath,
plugin: 'test-plugin',
version: '5.0.0-SNAPSHOT',
plugins: [ { name: 'foo', path: join(testWorkingPath, 'foo'), version: '5.0.0-SNAPSHOT' } ]
plugins: [ { name: 'foo', path: join(testWorkingPath, 'foo'), kibanaVersion: '5.0.0-SNAPSHOT' } ]
};
const errorStub = sinon.stub();

Expand All @@ -59,7 +59,7 @@ describe('kibana cli', function () {
expect(errorStub.called).to.be(false);
});

it('should throw an error if plugin does contain a version.', function () {
it('should throw an error if plugin is missing a kibana version.', function () {
const errorStub = sinon.stub();

try {
Expand All @@ -69,12 +69,12 @@ describe('kibana cli', function () {
errorStub(err);
}

expect(errorStub.firstCall.args[0]).to.match(/plugin version not found/i);
expect(errorStub.firstCall.args[0]).to.match(/plugin package\.json is missing both a version property/i);
});

it('should throw an error if plugin version does does not match kibana version', function () {
it('should throw an error if plugin kibanaVersion does not match kibana version', function () {
const errorStub = sinon.stub();
settings.plugins[0].version = '1.2.3.4';
settings.plugins[0].kibanaVersion = '1.2.3.4';

try {
assertVersion(settings);
Expand All @@ -83,12 +83,12 @@ describe('kibana cli', function () {
errorStub(err);
}

expect(errorStub.firstCall.args[0]).to.match(/incorrect version/i);
expect(errorStub.firstCall.args[0]).to.match(/incorrect kibana version/i);
});

it('should not throw an error if plugin version matches kibana version', function () {
it('should not throw an error if plugin kibanaVersion matches kibana version', function () {
const errorStub = sinon.stub();
settings.plugins[0].version = '1.0.0';
settings.plugins[0].kibanaVersion = '1.0.0';

try {
assertVersion(settings);
Expand All @@ -102,7 +102,7 @@ describe('kibana cli', function () {

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';
settings.plugins[0].kibanaVersion = '1.0.0-foo-bar-version-1.2.3';

try {
assertVersion(settings);
Expand All @@ -116,7 +116,7 @@ describe('kibana cli', function () {

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';
settings.plugins[0].kibanaVersion = '2.0.0-foo-bar-version-1.2.3';

try {
assertVersion(settings);
Expand All @@ -125,7 +125,7 @@ describe('kibana cli', function () {
errorStub(err);
}

expect(errorStub.firstCall.args[0]).to.match(/incorrect version/i);
expect(errorStub.firstCall.args[0]).to.match(/incorrect kibana version/i);
});
});

Expand Down
58 changes: 46 additions & 12 deletions src/cli_plugin/install/__tests__/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,41 @@ describe('kibana cli', function () {

describe('pack', function () {

const testWorkingPath = join(__dirname, '.test.data');
const tempArchiveFilePath = join(testWorkingPath, 'archive.part');
const testPluginPath = join(testWorkingPath, '.installedPlugins');
let testNum = 0;
const workingPathRoot = join(__dirname, '.test.data');
let testWorkingPath;
let tempArchiveFilePath;
let testPluginPath;
let logger;

const settings = {
workingPath: testWorkingPath,
tempArchiveFile: tempArchiveFilePath,
pluginDir: testPluginPath,
plugin: 'test-plugin'
};
let settings;

beforeEach(function () {
//These tests are dependent on the file system, and I had some inconsistent
//behavior with rimraf.sync show up. Until these tests are re-written to not
//depend on the file system, I make sure that each test uses a different
//working directory.
testNum += 1;
testWorkingPath = join(workingPathRoot, testNum + '');
tempArchiveFilePath = join(testWorkingPath, 'archive.part');
testPluginPath = join(testWorkingPath, '.installedPlugins');

settings = {
workingPath: testWorkingPath,
tempArchiveFile: tempArchiveFilePath,
pluginDir: testPluginPath,
plugin: 'test-plugin'
};

logger = new Logger(settings);
sinon.stub(logger, 'log');
sinon.stub(logger, 'error');
rimraf.sync(testWorkingPath);
mkdirp.sync(testWorkingPath);
});

afterEach(function () {
logger.log.restore();
logger.error.restore();
rimraf.sync(testWorkingPath);
rimraf.sync(workingPathRoot);
});

function copyReplyFile(filename) {
Expand Down Expand Up @@ -89,10 +100,33 @@ describe('kibana cli', function () {
expect(settings.plugins[0].name).to.be('test-plugin');
expect(settings.plugins[0].folder).to.be('test-plugin');
expect(settings.plugins[0].version).to.be('1.0.0');
expect(settings.plugins[0].kibanaVersion).to.be('1.0.0');
expect(settings.plugins[0].platform).to.be(undefined);
});
});

it('populate settings.plugin.kibanaVersion', function () {
//kibana.version is defined in this package.json and is different than plugin version
return copyReplyFile('test_plugin_different_version.zip')
.then(() => {
return getPackData(settings, logger);
})
.then(() => {
expect(settings.plugins[0].kibanaVersion).to.be('5.0.1');
});
});

it('populate settings.plugin.kibanaVersion (default to plugin version)', function () {
//kibana.version is not defined in this package.json, defaults to plugin version
return copyReplyFile('test_plugin.zip')
.then(() => {
return getPackData(settings, logger);
})
.then(() => {
expect(settings.plugins[0].kibanaVersion).to.be('1.0.0');
});
});

it('populate settings.plugins with multiple plugins', function () {
return copyReplyFile('test_plugin_many.zip')
.then(() => {
Expand Down
Binary file not shown.
8 changes: 4 additions & 4 deletions src/cli_plugin/install/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export async function rebuildCache(settings, logger) {
}

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].kibanaVersion) {
throw new Error (`Plugin package.json is missing both a version property (required) and a kibana.version property (optional).`);
}

const actual = cleanVersion(settings.plugins[0].version);
const actual = cleanVersion(settings.plugins[0].kibanaVersion);
const expected = cleanVersion(settings.version);
if (!versionSatisfies(actual, expected)) {
throw new Error (`Incorrect version in plugin [${settings.plugins[0].name}]. ` +
throw new Error (`Incorrect Kibana version in plugin [${settings.plugins[0].name}]. ` +
`Expected [${expected}]; found [${actual}]`);
}
}
10 changes: 8 additions & 2 deletions src/cli_plugin/install/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ function assertValidPackageName(plugin) {
}
}


/**
* Examine each package.json file to determine the plugin name,
* version, and platform. Mutates the package objects in the packages array
* version, kibanaVersion, and platform. Mutates the package objects
* in the packages array
* @param {object} settings - a plugin installer settings object
* @param {array} packages - array of package objects from listPackages()
*/
Expand All @@ -71,6 +71,12 @@ async function mergePackageData(settings, packages) {
pkg.name = _.get(packageInfo, 'name');
pkg.path = resolve(settings.pluginDir, pkg.name);

// Plugins must specify their version, and by default that version should match
// the version of kibana down to the patch level. If these two versions need
// to diverge, they can specify a kibana.version to indicate the version of
// kibana the plugin is intended to work with.
pkg.kibanaVersion = _.get(packageInfo, 'kibana.version', pkg.version);

const regExp = new RegExp(`${pkg.name}-(.+)`, 'i');
const matches = pkg.folder.match(regExp);
pkg.platform = (matches) ? matches[1] : undefined;
Expand Down

0 comments on commit 90ad531

Please sign in to comment.