mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-13 03:28:33 -05:00
DacFx integration tests (#6049)
* tests working * add bacpac * formatting * addressing comments * ignore bacpacs for hygiene check * add check for error message when checking for db creation * adding comments
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import assert = require('assert');
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as fs from 'fs';
|
||||
import { TestServerProfile } from './testConfig';
|
||||
|
||||
/**
|
||||
@@ -77,6 +78,12 @@ export async function deleteDB(dbName: string, ownerUri: string): Promise<void>
|
||||
await queryProvider.runQueryAndReturn(ownerUri, query);
|
||||
}
|
||||
|
||||
export async function runQuery(query: string, ownerUri: string): Promise<azdata.SimpleExecuteResult> {
|
||||
let queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>('MSSQL', azdata.DataProviderType.QueryProvider);
|
||||
let result = await queryProvider.runQueryAndReturn(ownerUri, query);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function assertThrowsAsync(fn: () => Promise<any>, msg: string): Promise<void> {
|
||||
let f = () => {
|
||||
// Empty
|
||||
@@ -89,3 +96,51 @@ export async function assertThrowsAsync(fn: () => Promise<any>, msg: string): Pr
|
||||
assert.throws(f, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databaseName name of database to check for
|
||||
* @param ownerUri owner uri
|
||||
* @param retryCount number of times to retry with a 5 second wait between each try
|
||||
* Checks for database getting created for operations that have async database creation
|
||||
*/
|
||||
export async function assertDatabaseCreationResult(databaseName: string, ownerUri: string, retryCount: number): Promise<void> {
|
||||
let result: azdata.SimpleExecuteResult;
|
||||
while (retryCount > 0) {
|
||||
--retryCount;
|
||||
await sleep(5000);
|
||||
|
||||
let query = `BEGIN TRY
|
||||
SELECT name FROM master.dbo.sysdatabases WHERE name='${databaseName}'
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
SELECT ERROR_MESSAGE() AS ErrorMessage;
|
||||
END CATCH`;
|
||||
result = await runQuery(query, ownerUri);
|
||||
if (result.rowCount > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(result.rowCount === 1, `Database ${databaseName} should be created`);
|
||||
assert(result.columnInfo[0].columnName !== 'ErrorMessage', 'Checking for db creation threw error');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filepath File path to check for
|
||||
* @param retryCount number of times to retry with a 5 second wait between each try
|
||||
* Checks for file getting created for async file generation and deletes file
|
||||
*/
|
||||
export async function assertFileGenerationResult(filepath: string, retryCount: number): Promise<void> {
|
||||
let exists = false;
|
||||
while (retryCount > 0 && !exists) {
|
||||
--retryCount;
|
||||
exists = fs.existsSync(filepath);
|
||||
await sleep(5000);
|
||||
}
|
||||
|
||||
assert(exists, `File ${filepath} is expected to be present`);
|
||||
assert(fs.readFileSync(filepath).byteLength > 0, 'File should not be empty');
|
||||
fs.unlinkSync(filepath);
|
||||
}
|
||||
Reference in New Issue
Block a user