mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
more test cases (#5545)
* toolsservice test * resource type tests * pr comments * comments
This commit is contained in:
@@ -44,7 +44,6 @@ export interface ToolRequirementInfo {
|
||||
}
|
||||
|
||||
export enum ToolType {
|
||||
Unknown,
|
||||
AzCli,
|
||||
KubeCtl,
|
||||
Docker,
|
||||
|
||||
@@ -8,6 +8,8 @@ import { ResourceType, ResourceTypeOption, DeploymentProvider } from '../interfa
|
||||
import { IToolsService } from './toolsService';
|
||||
import * as vscode from 'vscode';
|
||||
import { IPlatformService } from './platformService';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export interface IResourceTypeService {
|
||||
getResourceTypes(filterByPlatform?: boolean): ResourceType[];
|
||||
@@ -25,8 +27,18 @@ export class ResourceTypeService implements IResourceTypeService {
|
||||
*/
|
||||
getResourceTypes(filterByPlatform: boolean = true): ResourceType[] {
|
||||
if (this._resourceTypes.length === 0) {
|
||||
const pkgJson = require('../../package.json');
|
||||
let extensionFullName: string;
|
||||
if (pkgJson && pkgJson.name && pkgJson.publisher) {
|
||||
extensionFullName = `${pkgJson.publisher}.${pkgJson.name}`;
|
||||
} else {
|
||||
const errorMessage = localize('resourceDeployment.extensionFullNameError', 'Could not find package.json or the name/publisher is not set');
|
||||
this.platformService.showErrorMessage(errorMessage);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
// If we load package.json directly using require(path) the contents won't be localized
|
||||
this._resourceTypes = vscode.extensions.getExtension('microsoft.resource-deployment')!.packageJSON.resourceTypes as ResourceType[];
|
||||
this._resourceTypes = vscode.extensions.getExtension(extensionFullName)!.packageJSON.resourceTypes as ResourceType[];
|
||||
this._resourceTypes.forEach(resourceType => {
|
||||
resourceType.getProvider = (selectedOptions) => { return this.getProvider(resourceType, selectedOptions); };
|
||||
});
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import 'mocha';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import assert = require('assert');
|
||||
import { EOL } from 'os';
|
||||
import { ResourceTypeService } from '../services/resourceTypeService';
|
||||
import { IPlatformService } from '../services/platformService';
|
||||
import { ToolsService } from '../services/toolsService';
|
||||
|
||||
suite('Resource Type Service Tests', function (): void {
|
||||
|
||||
test('test resource types', () => {
|
||||
const mockPlatformService = TypeMoq.Mock.ofType<IPlatformService>();
|
||||
const toolsService = new ToolsService();
|
||||
const resourceTypeService = new ResourceTypeService(mockPlatformService.object, toolsService);
|
||||
// index 0: platform name, index 1: number of expected resource types
|
||||
const platforms: { platform: string; resourceTypeCount: number }[] = [
|
||||
{ platform: 'win32', resourceTypeCount: 2 },
|
||||
{ platform: 'darwin', resourceTypeCount: 2 },
|
||||
{ platform: 'linux', resourceTypeCount: 2 }];
|
||||
const totalResourceTypeCount = 2;
|
||||
platforms.forEach(platformInfo => {
|
||||
mockPlatformService.reset();
|
||||
mockPlatformService.setup(service => service.platform()).returns(() => platformInfo.platform);
|
||||
mockPlatformService.setup(service => service.showErrorMessage(TypeMoq.It.isAnyString()));
|
||||
const resourceTypes = resourceTypeService.getResourceTypes(true);
|
||||
assert.equal(resourceTypes.length, platformInfo.resourceTypeCount, `number of resource types for platform:${platformInfo.resourceTypeCount} does not meet expected value.`);
|
||||
});
|
||||
|
||||
const allResourceTypes = resourceTypeService.getResourceTypes(false);
|
||||
assert.equal(allResourceTypes.length, totalResourceTypeCount, `number of resource types does not meet expected value.`);
|
||||
|
||||
const validationErrors = resourceTypeService.validateResourceTypes(allResourceTypes);
|
||||
assert(validationErrors.length === 0, `Validation errors detected in the package.json: ${validationErrors.join(EOL)}.`);
|
||||
});
|
||||
});
|
||||
50
extensions/resource-deployment/src/test/toolsService.test.ts
Normal file
50
extensions/resource-deployment/src/test/toolsService.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import 'mocha';
|
||||
import assert = require('assert');
|
||||
import { ToolsService } from '../services/toolsService';
|
||||
import { ToolType } from '../interfaces';
|
||||
import { isNumber } from 'util';
|
||||
|
||||
suite('Tools Service Tests', function (): void {
|
||||
|
||||
test('run getToolByName with all known values', () => {
|
||||
const toolsService = new ToolsService();
|
||||
|
||||
const tools: { name: string; type: ToolType }[] = [
|
||||
{ name: 'azcli', type: ToolType.AzCli },
|
||||
{ name: 'docker', type: ToolType.Docker },
|
||||
{ name: 'kubectl', type: ToolType.KubeCtl },
|
||||
{ name: 'mssqlctl', type: ToolType.MSSQLCtl },
|
||||
{ name: 'python', type: ToolType.Python }];
|
||||
|
||||
const missingTypes: string[] = [];
|
||||
|
||||
// Make sure all the enum values are covered
|
||||
for (const type in ToolType) {
|
||||
if (isNumber(ToolType[type])) {
|
||||
if (tools.findIndex(element => element.type === parseInt(ToolType[type])) === -1) {
|
||||
missingTypes.push(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(missingTypes.length === 0, `the following enum values are not included in the test:${missingTypes.join(',')}`);
|
||||
|
||||
tools.forEach(toolInfo => {
|
||||
const tool = toolsService.getToolByName(toolInfo.name);
|
||||
assert(!!tool, `The tool: ${toolInfo.name} is not recognized`);
|
||||
assert.equal(tool!.type, toolInfo.type, 'returned notebook name does not match expected value');
|
||||
});
|
||||
});
|
||||
|
||||
test('run getToolByName with a name that is not defined', () => {
|
||||
const toolsService = new ToolsService();
|
||||
const tool = toolsService.getToolByName('no-such-tool');
|
||||
assert(tool === undefined, 'for a not defined tool, expected value is undefined');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user