From 5eb07e25c3b3e8a9f9a6c2ce738d65ad53f34f26 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Thu, 17 Jun 2021 11:15:25 +0200 Subject: [PATCH 1/2] [ML] Functional tests - fix and reenable module API tests --- .../api_integration/apis/ml/modules/index.ts | 6 +-- .../functional/services/ml/test_resources.ts | 44 ++++++++++++++++--- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/x-pack/test/api_integration/apis/ml/modules/index.ts b/x-pack/test/api_integration/apis/ml/modules/index.ts index f6c36c61b998c..1a0c532dc36fa 100644 --- a/x-pack/test/api_integration/apis/ml/modules/index.ts +++ b/x-pack/test/api_integration/apis/ml/modules/index.ts @@ -10,11 +10,9 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ getService, loadTestFile }: FtrProviderContext) { const ml = getService('ml'); - const fleetPackages = ['apache-0.5.0', 'nginx-0.5.0']; + const fleetPackages = ['apache', 'nginx']; - // Failing: See https://github.com/elastic/kibana/issues/102282 - // Failing: See https://github.com/elastic/kibana/issues/102283 - describe.skip('modules', function () { + describe('modules', function () { before(async () => { for (const fleetPackage of fleetPackages) { await ml.testResources.installFleetPackage(fleetPackage); diff --git a/x-pack/test/functional/services/ml/test_resources.ts b/x-pack/test/functional/services/ml/test_resources.ts index a857809a3079f..9b86eaea0898a 100644 --- a/x-pack/test/functional/services/ml/test_resources.ts +++ b/x-pack/test/functional/services/ml/test_resources.ts @@ -5,6 +5,7 @@ * 2.0. */ +import expect from '@kbn/expect'; import { ProvidedType } from '@kbn/test'; import { savedSearches, dashboards } from './test_resources_data'; import { COMMON_REQUEST_HEADERS } from './common_api'; @@ -533,26 +534,57 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider log.debug('> ML saved objects deleted.'); }, - async installFleetPackage(packageIdentifier: string) { - log.debug(`Installing Fleet package '${packageIdentifier}'`); + async installFleetPackage(packageName: string) { + log.debug(`Installing Fleet package '${packageName}'`); + + const version = await this.getFleetPackageVersion(packageName); await supertest - .post(`/api/fleet/epm/packages/${packageIdentifier}`) + .post(`/api/fleet/epm/packages/${packageName}-${version}`) .set(COMMON_REQUEST_HEADERS) .expect(200); log.debug(` > Installed`); }, - async removeFleetPackage(packageIdentifier: string) { - log.debug(`Removing Fleet package '${packageIdentifier}'`); + async removeFleetPackage(packageName: string) { + log.debug(`Removing Fleet package '${packageName}'`); + + const version = await this.getFleetPackageVersion(packageName); await supertest - .delete(`/api/fleet/epm/packages/${packageIdentifier}`) + .delete(`/api/fleet/epm/packages/${packageName}-${version}`) .set(COMMON_REQUEST_HEADERS) .expect(200); log.debug(` > Removed`); }, + + async getFleetPackageVersion(packageName: string): Promise { + log.debug(`Fetching version for Fleet package '${packageName}'`); + + const { body } = await supertest + .get(`/api/fleet/epm/packages?experimental=true`) + .set(COMMON_REQUEST_HEADERS) + .expect(200); + + let packageVersion: string = ''; + + for (const packageDefinition of body.response) { + if (packageDefinition.name === packageName) { + if (packageDefinition.version) { + log.debug(` > found version '${packageDefinition.version}'`); + packageVersion = packageDefinition.version as string; + break; + } + } + } + + expect(packageVersion).to.not.eql( + '', + `Fleet package definition for '${packageName}' should exist and have a version` + ); + return packageVersion; + }, }; } From aac44cc27c7e3adffc27690a3caadbd032fe7b43 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Thu, 17 Jun 2021 13:53:01 +0200 Subject: [PATCH 2/2] Improve code for package version finding --- .../functional/services/ml/test_resources.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/x-pack/test/functional/services/ml/test_resources.ts b/x-pack/test/functional/services/ml/test_resources.ts index 9b86eaea0898a..f1b2ef97e4e0d 100644 --- a/x-pack/test/functional/services/ml/test_resources.ts +++ b/x-pack/test/functional/services/ml/test_resources.ts @@ -568,22 +568,17 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider .set(COMMON_REQUEST_HEADERS) .expect(200); - let packageVersion: string = ''; - - for (const packageDefinition of body.response) { - if (packageDefinition.name === packageName) { - if (packageDefinition.version) { - log.debug(` > found version '${packageDefinition.version}'`); - packageVersion = packageDefinition.version as string; - break; - } - } - } + const packageVersion = + body.response.find( + ({ name, version }: { name: string; version: string }) => name === packageName && version + )?.version ?? ''; expect(packageVersion).to.not.eql( '', `Fleet package definition for '${packageName}' should exist and have a version` ); + + log.debug(` > found version '${packageVersion}'`); return packageVersion; }, };