Add more validation for DacFx tests (#6120)

* add checking for tables and data

* addressing comments
This commit is contained in:
Kim Santiago
2019-06-28 10:01:19 -07:00
committed by GitHub
parent 8cf4120c27
commit 53cd22f142
2 changed files with 60 additions and 3 deletions

View File

@@ -40,6 +40,8 @@ if (context.RunTest) {
// Deploy dacpac
const deployResult = await dacfxService.deployDacpac(path.join(__dirname, 'testData/Database1.dacpac'), databaseName, false, ownerUri, azdata.TaskExecutionMode.execute);
await utils.assertDatabaseCreationResult(databaseName, ownerUri, retryCount);
await utils.assertTableCreationResult(databaseName, 'dbo', 'Table1', ownerUri, retryCount);
await utils.assertTableCreationResult(databaseName, 'dbo', 'Table2', ownerUri, retryCount);
assert(deployResult.success === true && deployResult.errorMessage === '', `Deploy dacpac should succeed Expected: there should be no error. Actual Error message: "${deployResult.errorMessage}"`);
// Extract dacpac
@@ -74,6 +76,8 @@ if (context.RunTest) {
// Import bacpac
const importResult = await dacfxService.importBacpac(path.join(__dirname, 'testData/Database1.bacpac'), databaseName, ownerUri, azdata.TaskExecutionMode.execute);
await utils.assertDatabaseCreationResult(databaseName, ownerUri, retryCount);
await utils.assertTableCreationResult(databaseName, 'dbo', 'Table1', ownerUri, retryCount, true);
await utils.assertTableCreationResult(databaseName, 'dbo', 'Table2', ownerUri, retryCount, true);
assert(importResult.success === true && importResult.errorMessage === '', `Expected: Import bacpac should succeed and there should be no error. Actual Error message: "${importResult.errorMessage}"`);
// Export bacpac

View File

@@ -108,7 +108,6 @@ export async function assertDatabaseCreationResult(databaseName: string, ownerUr
let result: azdata.SimpleExecuteResult;
while (retryCount > 0) {
--retryCount;
await sleep(5000);
let query = `BEGIN TRY
SELECT name FROM master.dbo.sysdatabases WHERE name='${databaseName}'
@@ -120,6 +119,8 @@ export async function assertDatabaseCreationResult(databaseName: string, ownerUr
if (result.rowCount > 0) {
break;
}
await sleep(5000);
}
assert(result.rowCount === 1, `Database ${databaseName} should be created`);
@@ -141,6 +142,58 @@ export async function assertFileGenerationResult(filepath: string, retryCount: n
}
assert(exists, `File ${filepath} is expected to be present`);
assert(fs.readFileSync(filepath).byteLength > 0, 'File should not be empty');
assert(fs.readFileSync(filepath).byteLength > 0, 'File ${filepath} should not be empty');
fs.unlinkSync(filepath);
}
}
/**
*
* @param databaseName name of database where to look for table
* @param tableName table to look for
* @param schema schema to look for
* @param ownerUri owner uri
* @param retryCount number of times to retry with a 5 second wait between each try
* @param checkForData whether or not to check if the table has data
* Checks for table existing
*/
export async function assertTableCreationResult(databaseName: string, schema: string, tableName: string, ownerUri: string, retryCount: number, checkForData?: boolean): Promise<void> {
let result: azdata.SimpleExecuteResult;
while (retryCount > 0) {
--retryCount;
let query = `BEGIN TRY
USE ${databaseName}
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '${schema}' AND TABLE_NAME = '${tableName}'
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS ErrorMessage;
END CATCH`;
result = await runQuery(query, ownerUri);
if (result.rowCount > 0) {
break;
}
await sleep(5000);
}
assert(result.rowCount === 1, `Table ${tableName} should be created. ${result.rowCount} rows were found`);
assert(result.columnInfo[0].columnName !== 'ErrorMessage', `Checking for table creation threw error ${result.rows[0][0].displayValue}`);
if (checkForData) {
while (retryCount > 0) {
let query = `BEGIN TRY
USE ${databaseName}
SELECT * FROM ${tableName}
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS ErrorMessage;
END CATCH`;
result = await runQuery(query, ownerUri);
if (result.rowCount > 0) {
break;
}
await sleep(5000);
}
assert(result.rowCount > 0, `Table ${tableName} should have at least one row of data. ${result.rowCount} rows were found`);
assert(result.columnInfo[0].columnName !== 'ErrorMessage', `Checking for table creation threw error ${result.rows[0][0].displayValue}`);
}
}