From 4a54f53ae302670bf7e60bd14994cdf457366c3d Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 13 Mar 2020 17:05:05 -0700 Subject: [PATCH] Increase test coverage of admin-tool-ext-win (#9619) --- extensions/admin-tool-ext-win/src/main.ts | 4 +- .../admin-tool-ext-win/src/test/utils.test.ts | 44 +++++++++++++++++-- extensions/admin-tool-ext-win/src/utils.ts | 15 +++---- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/extensions/admin-tool-ext-win/src/main.ts b/extensions/admin-tool-ext-win/src/main.ts index e24741ef31..63d37e2a46 100644 --- a/extensions/admin-tool-ext-win/src/main.ts +++ b/extensions/admin-tool-ext-win/src/main.ts @@ -232,8 +232,8 @@ async function launchSsmsDialog(action: string, connectionContext: azdata.Object * @param params The params used to build up the command parameter string */ export function buildSsmsMinCommandArgs(params: LaunchSsmsDialogParams): string { - return `${params.action ? '-a "' + backEscapeDoubleQuotes(params.action) + '"' : ''}\ -${params.server ? ' -S "' + backEscapeDoubleQuotes(params.server) + '"' : ''}\ + return `-a "${backEscapeDoubleQuotes(params.action)}" \ +-S "${backEscapeDoubleQuotes(params.server)}"\ ${params.database ? ' -D "' + backEscapeDoubleQuotes(params.database) + '"' : ''}\ ${params.user ? ' -U "' + backEscapeDoubleQuotes(params.user) + '"' : ''}\ ${params.useAad === true ? ' -G' : ''}\ diff --git a/extensions/admin-tool-ext-win/src/test/utils.test.ts b/extensions/admin-tool-ext-win/src/test/utils.test.ts index f534f4e93d..015e2098b4 100644 --- a/extensions/admin-tool-ext-win/src/test/utils.test.ts +++ b/extensions/admin-tool-ext-win/src/test/utils.test.ts @@ -7,7 +7,7 @@ import * as should from 'should'; import 'mocha'; import { buildSsmsMinCommandArgs, buildUrn, LaunchSsmsDialogParams } from '../main'; -import { doubleEscapeSingleQuotes, backEscapeDoubleQuotes } from '../utils'; +import { doubleEscapeSingleQuotes, backEscapeDoubleQuotes, getTelemetryErrorType } from '../utils'; import { ExtHostObjectExplorerNodeStub } from './stubs'; describe('buildSsmsMinCommandArgs Method Tests', () => { @@ -73,13 +73,14 @@ const tableSchema = 'tbl\'sch'; const escapedTableSchema = doubleEscapeSingleQuotes(tableSchema); describe('buildUrn Method Tests', () => { - it('Urn should be correct with just server', async function (): Promise { + it('Urn should be correct with no node', async function (): Promise { should(await buildUrn(undefined)).equal('Server'); }); it('Urn should be correct with Server and only Databases folder', async function (): Promise { const leafNode: ExtHostObjectExplorerNodeStub = - new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined); + new ExtHostObjectExplorerNodeStub('MyServer', undefined, 'Server', undefined) + .createChild('Databases', undefined, 'Folder'); should(await buildUrn(leafNode)).equal('Server'); }); @@ -100,6 +101,16 @@ describe('buildUrn Method Tests', () => { should(await buildUrn(rootNode)).equal( `Server/Database[@Name='${escapedDbName}' and @Schema='${escapedDbSchema}']/Table[@Name='${escapedTableName}' and @Schema='${escapedTableSchema}']`); }); + + it('Urn should be correct with Multiple levels of Nodes without schemas', async function (): Promise { + const rootNode: ExtHostObjectExplorerNodeStub = + new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined) + .createChild(dbName, undefined, 'Database') + .createChild('Tables', undefined, 'Folder') + .createChild(tableName, undefined, 'Table'); + should(await buildUrn(rootNode)).equal( + `Server/Database[@Name='${escapedDbName}']/Table[@Name='${escapedTableName}']`); + }); }); describe('doubleEscapeSingleQuotes Method Tests', () => { @@ -129,3 +140,30 @@ describe('backEscapeDoubleQuotes Method Tests', () => { should(ret).equal('MyTestString\\"\\"WithQuotes'); }); }); + +describe('getTelemetryErrorType Method Tests', () => { + it('ExeNotFound', function (): void { + const msg = getTelemetryErrorType('SsmsMin.exe is not recognized as an internal or external command'); + should(msg).equal('ExeNotFound'); + }); + + it('UnknownAction', function (): void { + const msg = getTelemetryErrorType('Unknown Action "foo"'); + should(msg).equal('UnknownAction'); + }); + + it('NoActionProvided', function (): void { + const msg = getTelemetryErrorType('No Action Provided'); + should(msg).equal('NoActionProvided'); + }); + + it('RunException', function (): void { + const msg = getTelemetryErrorType('Run exception "Error occurred"'); + should(msg).equal('RunException'); + }); + + it('Other', function (): void { + const msg = getTelemetryErrorType('Some other error message'); + should(msg).equal('Other'); + }); +}); diff --git a/extensions/admin-tool-ext-win/src/utils.ts b/extensions/admin-tool-ext-win/src/utils.ts index 4f76e9a0df..954189de39 100644 --- a/extensions/admin-tool-ext-win/src/utils.ts +++ b/extensions/admin-tool-ext-win/src/utils.ts @@ -9,15 +9,12 @@ export interface IPackageInfo { aiKey: string; } -export function getPackageInfo(packageJson: any): IPackageInfo | undefined { - if (packageJson) { - return { - name: packageJson.name, - version: packageJson.version, - aiKey: packageJson.aiKey - }; - } - return undefined; +export function getPackageInfo(packageJson: any): IPackageInfo { + return { + name: packageJson.name, + version: packageJson.version, + aiKey: packageJson.aiKey + }; } /**