mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 09:35:41 -05:00
add some unit test for resource deployment ext (#11604)
* add some unit test for resource deployment ext * feedback & remove unused method
This commit is contained in:
@@ -408,6 +408,7 @@
|
||||
"mocha-junit-reporter": "^1.17.0",
|
||||
"mocha-multi-reporters": "^1.1.7",
|
||||
"typemoq": "^2.1.0",
|
||||
"vscodetestcover": "^1.0.9"
|
||||
"vscodetestcover": "^1.0.9",
|
||||
"should": "^13.2.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ export interface BdcEndpoint {
|
||||
|
||||
export interface IAzdataService {
|
||||
getDeploymentProfiles(deploymentType: BdcDeploymentType): Promise<BigDataClusterDeploymentProfile[]>;
|
||||
getEndpoints(clusterName: string, userName: string, password: string): Promise<BdcEndpoint[]>;
|
||||
}
|
||||
|
||||
export class AzdataService implements IAzdataService {
|
||||
@@ -73,16 +72,4 @@ export class AzdataService implements IAzdataService {
|
||||
private async getJsonObjectFromFile(path: string): Promise<any> {
|
||||
return JSON.parse(await this.platformService.readTextFile(path));
|
||||
}
|
||||
|
||||
public async getEndpoints(clusterName: string, userName: string, password: string): Promise<BdcEndpoint[]> {
|
||||
const env: NodeJS.ProcessEnv = {};
|
||||
env['AZDATA_USERNAME'] = userName;
|
||||
env['AZDATA_PASSWORD'] = password;
|
||||
env['ACCEPT_EULA'] = 'yes';
|
||||
let cmd = 'azdata login -n ' + clusterName;
|
||||
await this.platformService.runCommand(cmd, { additionalEnvironmentVariables: env });
|
||||
cmd = 'azdata bdc endpoint list';
|
||||
const stdout = await this.platformService.runCommand(cmd, { additionalEnvironmentVariables: env });
|
||||
return <BdcEndpoint[]>JSON.parse(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
16
extensions/resource-deployment/src/test/apiService.test.ts
Normal file
16
extensions/resource-deployment/src/test/apiService.test.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import 'mocha';
|
||||
import assert = require('assert');
|
||||
import { apiService } from '../services/apiService';
|
||||
|
||||
suite('API Service Tests', function (): void {
|
||||
|
||||
test('getAzurecoreApi returns azure api', async () => {
|
||||
const api = await apiService.getAzurecoreApi();
|
||||
assert(api !== undefined);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import 'mocha';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as should from 'should';
|
||||
import { IPlatformService, CommandOptions } from '../services/platformService';
|
||||
import { AzdataService } from '../services/azdataService';
|
||||
import { BdcDeploymentType } from '../interfaces';
|
||||
|
||||
suite('azdata service Tests', function (): void {
|
||||
test('azdata service handles deployment types properly', async () => {
|
||||
const mockPlatformService = TypeMoq.Mock.ofType<IPlatformService>();
|
||||
const azdataService = new AzdataService(mockPlatformService.object);
|
||||
mockPlatformService.setup((service) => service.runCommand(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns((command: string, options: CommandOptions | undefined) => {
|
||||
return new Promise<string>((resolve) => {
|
||||
resolve('{"result":[]}');
|
||||
});
|
||||
});
|
||||
|
||||
azdataService.getDeploymentProfiles(BdcDeploymentType.ExistingAKS);
|
||||
azdataService.getDeploymentProfiles(BdcDeploymentType.ExistingARO);
|
||||
azdataService.getDeploymentProfiles(BdcDeploymentType.ExistingKubeAdm);
|
||||
azdataService.getDeploymentProfiles(BdcDeploymentType.ExistingOpenShift);
|
||||
azdataService.getDeploymentProfiles(BdcDeploymentType.NewAKS);
|
||||
|
||||
should(azdataService.getDeploymentProfiles(<BdcDeploymentType>'no-such-type')).rejected();
|
||||
mockPlatformService.verify((service) => service.runCommand(TypeMoq.It.isAnyString(), TypeMoq.It.isAny()), TypeMoq.Times.exactly(5));
|
||||
});
|
||||
|
||||
test('azdata service returns correct deployment profiles', async () => {
|
||||
const mockPlatformService = TypeMoq.Mock.ofType<IPlatformService>();
|
||||
const azdataService = new AzdataService(mockPlatformService.object);
|
||||
mockPlatformService.setup((service => service.storagePath())).returns(() => {
|
||||
return '';
|
||||
});
|
||||
mockPlatformService.setup((service => service.readTextFile(TypeMoq.It.isAnyString()))).returns((path: string) => {
|
||||
return new Promise<string>((resolve) => {
|
||||
resolve('{}');
|
||||
});
|
||||
});
|
||||
mockPlatformService.setup((service) => service.runCommand(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns((command: string, options: CommandOptions | undefined) => {
|
||||
if (command === 'azdata bdc config list -o json') {
|
||||
return Promise.resolve('{"result":["aks-1","profile-2"]}');
|
||||
} else if (command.startsWith('azdata bdc config init')) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
else {
|
||||
return Promise.reject(`unexpected command: ${command}`);
|
||||
}
|
||||
});
|
||||
const profiles = await azdataService.getDeploymentProfiles(BdcDeploymentType.NewAKS);
|
||||
should(profiles.length).be.exactly(1);
|
||||
});
|
||||
});
|
||||
@@ -694,6 +694,50 @@ semver@^6.0.0, semver@^6.3.0:
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
||||
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
|
||||
|
||||
should-equal@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/should-equal/-/should-equal-2.0.0.tgz#6072cf83047360867e68e98b09d71143d04ee0c3"
|
||||
integrity sha512-ZP36TMrK9euEuWQYBig9W55WPC7uo37qzAEmbjHz4gfyuXrEUgF8cUvQVO+w+d3OMfPvSRQJ22lSm8MQJ43LTA==
|
||||
dependencies:
|
||||
should-type "^1.4.0"
|
||||
|
||||
should-format@^3.0.3:
|
||||
version "3.0.3"
|
||||
resolved "https://registry.yarnpkg.com/should-format/-/should-format-3.0.3.tgz#9bfc8f74fa39205c53d38c34d717303e277124f1"
|
||||
integrity sha1-m/yPdPo5IFxT04w01xcwPidxJPE=
|
||||
dependencies:
|
||||
should-type "^1.3.0"
|
||||
should-type-adaptors "^1.0.1"
|
||||
|
||||
should-type-adaptors@^1.0.1:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/should-type-adaptors/-/should-type-adaptors-1.1.0.tgz#401e7f33b5533033944d5cd8bf2b65027792e27a"
|
||||
integrity sha512-JA4hdoLnN+kebEp2Vs8eBe9g7uy0zbRo+RMcU0EsNy+R+k049Ki+N5tT5Jagst2g7EAja+euFuoXFCa8vIklfA==
|
||||
dependencies:
|
||||
should-type "^1.3.0"
|
||||
should-util "^1.0.0"
|
||||
|
||||
should-type@^1.3.0, should-type@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/should-type/-/should-type-1.4.0.tgz#0756d8ce846dfd09843a6947719dfa0d4cff5cf3"
|
||||
integrity sha1-B1bYzoRt/QmEOmlHcZ36DUz/XPM=
|
||||
|
||||
should-util@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/should-util/-/should-util-1.0.1.tgz#fb0d71338f532a3a149213639e2d32cbea8bcb28"
|
||||
integrity sha512-oXF8tfxx5cDk8r2kYqlkUJzZpDBqVY/II2WhvU0n9Y3XYvAYRmeaf1PvvIvTgPnv4KJ+ES5M0PyDq5Jp+Ygy2g==
|
||||
|
||||
should@^13.2.3:
|
||||
version "13.2.3"
|
||||
resolved "https://registry.yarnpkg.com/should/-/should-13.2.3.tgz#96d8e5acf3e97b49d89b51feaa5ae8d07ef58f10"
|
||||
integrity sha512-ggLesLtu2xp+ZxI+ysJTmNjh2U0TsC+rQ/pfED9bUZZ4DKefP27D+7YJVVTvKsmjLpIi9jAa7itwDGkDDmt1GQ==
|
||||
dependencies:
|
||||
should-equal "^2.0.0"
|
||||
should-format "^3.0.3"
|
||||
should-type "^1.4.0"
|
||||
should-type-adaptors "^1.0.1"
|
||||
should-util "^1.0.0"
|
||||
|
||||
source-map@^0.5.0:
|
||||
version "0.5.7"
|
||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
|
||||
|
||||
Reference in New Issue
Block a user