Skip to content

Commit

Permalink
[ML] Functional tests - fix and re-enable module API tests (elastic#1…
Browse files Browse the repository at this point in the history
…02477)

This PR fixes and re-enables the temporarily skipped API test suite for ML modules.
  • Loading branch information
pheyos authored and kibanamachine committed Jun 17, 2021
1 parent 2502303 commit 7cc7ab4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/ml/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
39 changes: 33 additions & 6 deletions x-pack/test/functional/services/ml/test_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -533,26 +534,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<string> {
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;
},
};
}

0 comments on commit 7cc7ab4

Please sign in to comment.