Skip to content

Commit

Permalink
[ML] Move get_module Jest tests to functional API test (#61613) (#61637)
Browse files Browse the repository at this point in the history
This PR removes the flaky listModules and getModule Jest tests and adds them as functional API tests.
  • Loading branch information
pheyos authored Mar 27, 2020
1 parent cb3a791 commit 8f27436
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,6 @@ describe('ML - data recognizer', () => {
} as never) as SavedObjectsClientContract
);

const moduleIds = [
'apache_ecs',
'apm_jsbase',
'apm_nodejs',
'apm_transaction',
'auditbeat_process_docker_ecs',
'auditbeat_process_hosts_ecs',
'logs_ui_analysis',
'logs_ui_categories',
'metricbeat_system_ecs',
'nginx_ecs',
'sample_data_ecommerce',
'sample_data_weblogs',
'siem_auditbeat',
'siem_auditbeat_auth',
'siem_packetbeat',
'siem_winlogbeat',
'siem_winlogbeat_auth',
'uptime_heartbeat',
];

// check all module IDs are the same as the list above
it('listModules - check all module IDs', async () => {
const modules = await dr.listModules();
const ids = modules.map(m => m.id);
expect(ids.join()).toEqual(moduleIds.join());
});

it('getModule - load a single module', async () => {
const module = await dr.getModule(moduleIds[0]);
expect(module.id).toEqual(moduleIds[0]);
});

describe('jobOverrides', () => {
it('should apply job overrides correctly', () => {
// arrange
Expand Down
70 changes: 70 additions & 0 deletions x-pack/test/api_integration/apis/ml/get_module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';

import { FtrProviderContext } from '../../ftr_provider_context';
import { USER } from '../../../functional/services/machine_learning/security_common';

const COMMON_HEADERS = {
'kbn-xsrf': 'some-xsrf-token',
};

const moduleIds = [
'apache_ecs',
'apm_jsbase',
'apm_nodejs',
'apm_transaction',
'auditbeat_process_docker_ecs',
'auditbeat_process_hosts_ecs',
'logs_ui_analysis',
'logs_ui_categories',
'metricbeat_system_ecs',
'nginx_ecs',
'sample_data_ecommerce',
'sample_data_weblogs',
'siem_auditbeat',
'siem_auditbeat_auth',
'siem_packetbeat',
'siem_winlogbeat',
'siem_winlogbeat_auth',
'uptime_heartbeat',
];

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertestWithoutAuth');
const mlSecurity = getService('mlSecurity');

async function executeGetModuleRequest(module: string, user: USER, rspCode: number) {
const { body } = await supertest
.get(`/api/ml/modules/get_module/${module}`)
.auth(user, mlSecurity.getPasswordForUser(user))
.set(COMMON_HEADERS)
.expect(rspCode);

return body;
}

describe('get_module', function() {
it('lists all modules', async () => {
const rspBody = await executeGetModuleRequest('', USER.ML_POWERUSER, 200);
expect(rspBody).to.be.an(Array);

const responseModuleIds = rspBody.map((module: { id: string }) => module.id);
expect(responseModuleIds).to.eql(moduleIds);
});

for (const moduleId of moduleIds) {
it(`loads module ${moduleId}`, async () => {
const rspBody = await executeGetModuleRequest(moduleId, USER.ML_POWERUSER, 200);
expect(rspBody).to.be.an(Object);

expect(rspBody.id).to.eql(moduleId);
});
}
});
};
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export default function({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./bucket_span_estimator'));
loadTestFile(require.resolve('./calculate_model_memory_limit'));
loadTestFile(require.resolve('./categorization_field_examples'));
loadTestFile(require.resolve('./get_module'));
});
}

0 comments on commit 8f27436

Please sign in to comment.