Skip to content

Commit

Permalink
fixed bug with comparing upgrade version with snapshot kibana version (
Browse files Browse the repository at this point in the history
…#139007)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
juliaElastic and kibanamachine authored Aug 17, 2022
1 parent 3f58b47 commit 2fab204
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions x-pack/plugins/fleet/server/routes/agent/upgrade_handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { checkKibanaVersion } from './upgrade_handler';

describe('upgrade handler', () => {
describe('checkKibanaVersion', () => {
it('should not throw if upgrade version is equal to kibana version', () => {
expect(() => checkKibanaVersion('8.4.0', '8.4.0')).not.toThrowError();
});

it('should throw if upgrade version is higher than kibana version', () => {
expect(() => checkKibanaVersion('8.5.0', '8.4.0')).toThrowError(
'cannot upgrade agent to 8.5.0 because it is higher than the installed kibana version 8.4.0'
);
});

it('should not throw if upgrade version is equal to kibana version with snapshot', () => {
expect(() => checkKibanaVersion('8.4.0', '8.4.0-SNAPSHOT')).not.toThrowError();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const checkKibanaVersion = (version: string, kibanaVersion: string) => {
if (!versionToUpgradeNumber)
throw new Error(`version to upgrade ${versionToUpgradeNumber} is not valid`);

if (semverGt(version, kibanaVersion))
if (semverGt(versionToUpgradeNumber, kibanaVersionNumber))
throw new Error(
`cannot upgrade agent to ${versionToUpgradeNumber} because it is higher than the installed kibana version ${kibanaVersionNumber}`
);
Expand Down

0 comments on commit 2fab204

Please sign in to comment.