mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -05:00
Fixing bug where templates may get mapped before loaded from their files (#10111)
* Fixing potential bad order of template loading and map construction * Fixing bug where templates get mapped before loaded from file * Parallelizing loading templates from file
This commit is contained in:
39
extensions/sql-database-projects/src/test/templates.test.ts
Normal file
39
extensions/sql-database-projects/src/test/templates.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as should from 'should';
|
||||
import * as path from 'path';
|
||||
import * as templates from '../templates/templates';
|
||||
import { shouldThrowSpecificError } from './testUtils';
|
||||
|
||||
describe('Templates: loading templates from disk', function (): void {
|
||||
beforeEach(() => {
|
||||
templates.reset();
|
||||
});
|
||||
|
||||
it('Should throw error when attempting to use templates before loaded from file', async function (): Promise<void> {
|
||||
shouldThrowSpecificError(() => templates.projectScriptTypeMap(), 'Templates must be loaded from file before attempting to use.');
|
||||
shouldThrowSpecificError(() => templates.projectScriptTypes(), 'Templates must be loaded from file before attempting to use.');
|
||||
});
|
||||
|
||||
it('Should load all templates from files', async function (): Promise<void> {
|
||||
await templates.loadTemplates(path.join(__dirname, '..', '..', 'resources', 'templates'));
|
||||
|
||||
// check expected counts
|
||||
|
||||
const numScriptObjectTypes = 4;
|
||||
|
||||
should(templates.projectScriptTypes().length).equal(numScriptObjectTypes);
|
||||
should(Object.keys(templates.projectScriptTypes()).length).equal(numScriptObjectTypes);
|
||||
|
||||
// check everything has a value
|
||||
|
||||
should(templates.newSqlProjectTemplate).not.equal(undefined);
|
||||
|
||||
for (const obj of templates.projectScriptTypes()) {
|
||||
should(obj.templateScript).not.equal(undefined);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,23 @@ import * as os from 'os';
|
||||
import * as constants from '../common/constants';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import should = require('should');
|
||||
import { AssertionError } from 'assert';
|
||||
|
||||
export function shouldThrowSpecificError(block: Function, expectedMessage: string) {
|
||||
let succeeded = false;
|
||||
try {
|
||||
block();
|
||||
succeeded = true;
|
||||
}
|
||||
catch (err) {
|
||||
should(err.message).equal(expectedMessage);
|
||||
}
|
||||
|
||||
if (succeeded) {
|
||||
throw new AssertionError({ message: 'Operation succeeded, but expected failure with exception: "' + expectedMessage + '"' });
|
||||
}
|
||||
}
|
||||
|
||||
export async function createTestSqlProj(contents: string, folderPath?: string): Promise<string> {
|
||||
return await createTestFile(contents, 'TestProject.sqlproj', folderPath);
|
||||
|
||||
Reference in New Issue
Block a user