mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
platformService tests and move tests from tdd to bdd (#13131)
This commit is contained in:
@@ -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';
|
||||
|
||||
describe('azdata service Tests', function (): void {
|
||||
it('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));
|
||||
});
|
||||
|
||||
it('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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user