Skip to content

Commit

Permalink
updates for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jun 9, 2020
1 parent 0f09af2 commit ec910b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isCloud,
getNewJobDefaults,
getNewJobLimits,
extractDeploymentId,
} from './ml_server_info';
import mockMlInfoResponse from './__mocks__/ml_info_response.json';

Expand Down Expand Up @@ -59,4 +60,24 @@ describe('ml_server_info', () => {
done();
});
});

describe('cloud extract deployment ID', () => {
const cloudIdWithDeploymentName =
'cloud_message_test:ZXUtd2VzdC0yLmF3cy5jbG91ZC5lcy5pbyQ4NWQ2NjZmMzM1MGM0NjllOGMzMjQyZDc2YTdmNDU5YyQxNmI1ZDM2ZGE1Mzk0YjlkYjIyZWJlNDk1OWY1OGQzMg==';

const cloudIdWithOutDeploymentName =
':ZXUtd2VzdC0yLmF3cy5jbG91ZC5lcy5pbyQ4NWQ2NjZmMzM1MGM0NjllOGMzMjQyZDc2YTdmNDU5YyQxNmI1ZDM2ZGE1Mzk0YjlkYjIyZWJlNDk1OWY1OGQzMg==';

it('cloud ID with deployment name', () => {
expect(extractDeploymentId(cloudIdWithDeploymentName)).toBe(
'85d666f3350c469e8c3242d76a7f459c'
);
});

it('cloud ID without deployment name', () => {
expect(extractDeploymentId(cloudIdWithOutDeploymentName)).toBe(
'85d666f3350c469e8c3242d76a7f459c'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export function isCloud(): boolean {
}

export function getCloudDeploymentId(): string | null {
if (cloudInfo.cloudId === null) {
return null;
}
const tempCloudId = cloudInfo.cloudId.replace(/^(.+)?:/, '');
return cloudInfo.cloudId === null ? null : extractDeploymentId(cloudInfo.cloudId);
}

export function extractDeploymentId(cloudId: string) {
const tempCloudId = cloudId.replace(/^(.+)?:/, '');
try {
const matches = atob(tempCloudId).match(/^.+\$(.+)(?=\$)/);
return matches !== null && matches.length === 2 ? matches[1] : null;
Expand Down

0 comments on commit ec910b8

Please sign in to comment.