From fd5f62d90b10d1be4de7af45d46856fc61ff1ab2 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Thu, 17 Jun 2021 18:29:16 +0200 Subject: [PATCH] [ML] Functional tests - fix and re-enable module API tests (#102477) (#102515) This PR fixes and re-enables the temporarily skipped API test suite for ML modules. # Conflicts: # x-pack/test/functional/services/ml/test_resources.ts --- .../api_integration/apis/ml/modules/index.ts | 2 +- .../functional/services/ml/test_resources.ts | 39 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 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 ab46c4f0333c8..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,7 +10,7 @@ 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']; describe('modules', function () { before(async () => { diff --git a/x-pack/test/functional/services/ml/test_resources.ts b/x-pack/test/functional/services/ml/test_resources.ts index f967099e10fa3..cedb78630f0a3 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'; @@ -529,26 +530,52 @@ 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); + + 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; + }, }; }