Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Functional tests - fix and re-enable module API tests #102477

Merged
merged 2 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions x-pack/test/api_integration/apis/ml/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 38 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,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<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);

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;
}
}
}
Copy link
Member

@jgowdyelastic jgowdyelastic Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, this could be written with less code.

for (const { name, version } of body.response) {
   if (name === packageName && version) {
     log.debug(` > found version '${version}'`);
     packageVersion = version as string;
     break;
  }
}

or even something like

const packageVersion = body.response.find(({name, version}) => name === packageName && version)?.version ?? ''

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in aac44cc


expect(packageVersion).to.not.eql(
'',
`Fleet package definition for '${packageName}' should exist and have a version`
);
return packageVersion;
},
};
}