fixed bug with comparing upgrade version with snapshot kibana version (#139007) (#139011)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 2fab2041c4)

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2022-08-17 12:00:46 -04:00 committed by GitHub
parent 0f61496666
commit 391d999075
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -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();
});
});
});

View file

@ -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}`
);