Tests for Schema Compare utils file (#10822)

* Introduced ApiWrapper for testability

* Added tests for coverage of utils.ts

* Addressed comments
This commit is contained in:
Sakshi Sharma
2020-06-11 10:16:22 -07:00
committed by GitHub
parent bb244e4b91
commit f862d77f34
9 changed files with 261 additions and 40 deletions

View File

@@ -5,9 +5,11 @@
import * as azdata from 'azdata';
import * as mssql from '../../../mssql';
import should = require('should');
import { AssertionError } from 'assert';
// Mock test data
export const mockConnectionProfile: azdata.IConnectionProfile = {
export const mockIConnectionProfile: azdata.IConnectionProfile = {
connectionName: 'My Connection',
serverName: 'My Server',
databaseName: 'My Database',
@@ -23,6 +25,35 @@ export const mockConnectionProfile: azdata.IConnectionProfile = {
options: null
};
export const mockConnectionProfile: azdata.connection.ConnectionProfile = {
providerId: 'My Provider',
connectionId: 'My Id',
connectionName: 'My Connection',
serverName: 'My Server',
databaseName: 'My Database',
userName: 'My User',
password: 'My Pwd',
authenticationType: 'SqlLogin',
savePassword: false,
groupFullName: 'My groupName',
groupId: 'My GroupId',
saveProfile: true,
options: {
server: 'My Server',
database: 'My Database',
user: 'My User',
password: 'My Pwd',
authenticationType: 'SqlLogin'
}
};
export const mockConnectionResult: azdata.ConnectionResult = {
connected: false,
connectionId: undefined,
errorMessage: 'Login failed for user \'sa\'',
errorCode: 18456
};
export const mockConnectionInfo = {
options: {},
serverName: 'My Server',
@@ -53,3 +84,18 @@ export const mockDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {
packageFilePath: '',
connectionDetails: undefined
};
export async function shouldThrowSpecificError(block: Function, expectedMessage: string, details?: string) {
let succeeded = false;
try {
await block();
succeeded = true;
}
catch (err) {
should(err.message).equal(expectedMessage);
}
if (succeeded) {
throw new AssertionError({ message: `Operation succeeded, but expected failure with exception: "${expectedMessage}".${details ? ' ' + details : ''}` });
}
}