Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Oct 31, 2019
1 parent 68f7d34 commit 826299e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"defaults": {
"anomaly_detectors": {
"model_memory_limit": "128mb",
"categorization_examples_limit": 4,
"model_snapshot_retention_days": 1
},
"datafeeds": {
"scroll_size": 1000
}
},
"upgrade_mode": false,
"native_code": {
"version": "8.0.0-SNAPSHOT",
"build_hash": "4cde1d7c50fc28"
},
"limits": {
"max_model_memory_limit": "128mb"
},
"cloudId": "cloud_message_test:ZXUtd2VzdC0yLmF3cy5jbG91ZC5lcy5pbyQ4NWQ2NjZmMzM1MGM0NjllOGMzMjQyZDc2YTdmNDU5YyQxNmI1ZDM2ZGE1Mzk0YjlkYjIyZWJlNDk1OWY1OGQzMg=="
}
57 changes: 57 additions & 0 deletions x-pack/legacy/plugins/ml/public/services/ml_server_info.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 {
loadMlServerInfo,
cloudDeploymentId,
isCloud,
newJobDefaults,
newJobLimits,
} from './ml_server_info';
import mockMlInfoResponse from './__mocks__/ml_info_response.json';

jest.mock('./ml_api_service', () => ({
ml: {
mlInfo: jest.fn(() => Promise.resolve(mockMlInfoResponse)),
},
}));

describe('ml_server_info', () => {
it('server info not loaded ', async done => {
expect(isCloud()).toBe(false);
expect(cloudDeploymentId()).toBe(null);

// now load the info for the other tests
await loadMlServerInfo();
done();
});

describe('cloud information', () => {
it('can get could deployment id', () => {
expect(isCloud()).toBe(true);
expect(cloudDeploymentId()).toBe('85d666f3350c469e8c3242d76a7f459c');
});
});

describe('defaults', () => {
it('can get defaults', () => {
const defaults = newJobDefaults();

expect(defaults.anomaly_detectors.model_memory_limit).toBe('128mb');
expect(defaults.anomaly_detectors.categorization_examples_limit).toBe(4);
expect(defaults.anomaly_detectors.model_snapshot_retention_days).toBe(1);
expect(defaults.datafeeds.scroll_size).toBe(1000);
});
});

describe('limits', () => {
it('can get limits', () => {
const limits = newJobLimits();

expect(limits.max_model_memory_limit).toBe('128mb');
});
});
});
20 changes: 0 additions & 20 deletions x-pack/legacy/plugins/ml/public/services/ml_server_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,3 @@ export function cloudDeploymentId(): string | null {
return null;
}
}

export function cloudDeploymentAddress(): string | null {
if (cloudInfo.cloudId === null) {
return null;
}

const tempCloudId = cloudInfo.cloudId.replace(/^.+:/, '');
try {
const matches = atob(tempCloudId).match(/^(.+?)\.(.+?)\..*?\$(.+)\$/);
if (matches && matches.length === 4) {
const region = matches[1];
const platform = matches[2];
const deploymentId = matches[3];
return `https://cloud.elastic.co/region/${platform}-${region}/deployment/${deploymentId}/edit`;
}
return null;
} catch (error) {
return null;
}
}

0 comments on commit 826299e

Please sign in to comment.