mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 01:25:36 -05:00
Cleanup generated test files and folders for Sql DB projects (#20862)
* Cleanup generated test files and folders * Add await to fix tests
This commit is contained in:
@@ -25,6 +25,10 @@ describe('Autorest tests', function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should detect autorest', async function (): Promise<void> {
|
||||
sinon.stub(window, 'showInformationMessage').returns(<any>Promise.resolve(runViaNpx)); // stub a selection in case test runner doesn't have autorest installed
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ describe('Data Sources: DataSource operations', function (): void {
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it.skip('Should read DataSources from datasource.json', async function (): Promise<void> {
|
||||
const dataSourcePath = await testUtils.createTestDataSources(baselines.openDataSourcesBaseline);
|
||||
const dataSourceList = await dataSources.load(dataSourcePath);
|
||||
|
||||
@@ -70,6 +70,10 @@ describe('deploy service', function (): void {
|
||||
sandbox = sinon.createSandbox();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should deploy a database to docker container successfully', async function (): Promise<void> {
|
||||
const testContext = createContext();
|
||||
const deployProfile: IPublishToDockerSettings = {
|
||||
|
||||
@@ -31,6 +31,10 @@ describe('Add Database Reference Dialog', () => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should open dialog successfully', async function (): Promise<void> {
|
||||
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
||||
const dialog = new AddDatabaseReferenceDialog(project);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import * as should from 'should';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as vscode from 'vscode';
|
||||
import * as baselines from '../baselines/baselines';
|
||||
import * as templates from '../../templates/templates';
|
||||
@@ -27,9 +26,13 @@ describe('Publish Database Dialog', () => {
|
||||
testContext = createContext();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should open dialog successfully ', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(testContext.outputChannel);
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
const projFileDir = path.join(testUtils.generateBaseFolderName(), `TestProject_${new Date().getTime()}`);
|
||||
|
||||
const projFilePath = await projController.createNewProject({
|
||||
newProjName: 'TestProjectName',
|
||||
@@ -48,7 +51,7 @@ describe('Publish Database Dialog', () => {
|
||||
it('Should create default database name correctly ', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(testContext.outputChannel);
|
||||
const projFolder = `TestProject_${new Date().getTime()}`;
|
||||
const projFileDir = path.join(os.tmpdir(), projFolder);
|
||||
const projFileDir = path.join(testUtils.generateBaseFolderName(), projFolder);
|
||||
|
||||
const projFilePath = await projController.createNewProject({
|
||||
newProjName: 'TestProjectName',
|
||||
|
||||
@@ -19,6 +19,10 @@ describe('Publish Database Options Dialog', () => {
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should open dialog successfully ', async function (): Promise<void> {
|
||||
const proj = new Project('');
|
||||
sinon.stub(proj, 'getProjectTargetVersion').returns('150');
|
||||
|
||||
@@ -21,6 +21,10 @@ describe('Update Project From Database Dialog', () => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should populate endpoints correctly when no context passed', async function (): Promise<void> {
|
||||
const dialog = new UpdateProjectFromDatabaseDialog(undefined, undefined);
|
||||
await dialog.openDialog();
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as vscode from 'vscode';
|
||||
import * as sinon from 'sinon';
|
||||
import { NetCoreTool, DBProjectConfigurationKey, DotnetInstallLocationKey } from '../tools/netcoreTool';
|
||||
import { getQuotedPath } from '../common/utils';
|
||||
import { generateTestFolderPath } from './testUtils';
|
||||
import { deleteGeneratedTestFolder, generateTestFolderPath } from './testUtils';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
|
||||
let testContext: TestContext;
|
||||
@@ -25,6 +25,10 @@ describe('NetCoreTool: Net core tests', function (): void {
|
||||
testContext = createContext();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should override dotnet default value with settings', async function (): Promise<void> {
|
||||
try {
|
||||
// update settings and validate
|
||||
|
||||
@@ -9,7 +9,7 @@ import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
import * as dataworkspace from 'dataworkspace';
|
||||
import * as newProjectTool from '../tools/newProjectTool';
|
||||
import { generateTestFolderPath, createTestFile } from './testUtils';
|
||||
import { generateTestFolderPath, createTestFile, deleteGeneratedTestFolder } from './testUtils';
|
||||
|
||||
let previousSetting : string;
|
||||
let testFolderPath : string;
|
||||
@@ -29,6 +29,10 @@ describe('NewProjectTool: New project tool tests', function (): void {
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object});
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
// reset the default project folder path to the previous setting
|
||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, previousSetting, true);
|
||||
|
||||
@@ -30,6 +30,10 @@ describe('Project: sqlproj content operations', function (): void {
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline);
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should read Project from sqlproj', async function (): Promise<void> {
|
||||
const project: Project = await Project.openProject(projFilePath);
|
||||
|
||||
@@ -914,6 +918,10 @@ describe('Project: sdk style project content operations', function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should read project from sqlproj and files and folders by globbing', async function (): Promise<void> {
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectBaseline);
|
||||
await testUtils.createDummyFileStructureWithPrePostDeployScripts(false, undefined, path.dirname(projFilePath));
|
||||
@@ -1551,6 +1559,7 @@ describe('Project: sdk style project content operations', function (): void {
|
||||
should(project.files.find(f => f.type === EntryType.File && f.relativePath === externalFileRelativePath)).not.equal(undefined);
|
||||
projFileText = (await fs.readFile(projFilePath)).toString();
|
||||
should(projFileText.includes(`<Build Include="${externalFileRelativePath}" />`)).equal(true, projFileText);
|
||||
await fs.rm(externalSqlFile);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1559,6 +1568,10 @@ describe('Project: add SQLCMD Variables', function (): void {
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should update .sqlproj with new sqlcmd variables', async function (): Promise<void> {
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline);
|
||||
const project = await Project.openProject(projFilePath);
|
||||
@@ -1584,6 +1597,10 @@ describe('Project: properties', function (): void {
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should read target database version', async function (): Promise<void> {
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline);
|
||||
const project = await Project.openProject(projFilePath);
|
||||
@@ -1749,6 +1766,10 @@ describe('Project: round trip updates', function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should update SSDT project to work in ADS', async function (): Promise<void> {
|
||||
await testUpdateInRoundTrip(baselines.SSDTProjectFileBaseline, baselines.SSDTProjectAfterUpdateBaseline);
|
||||
});
|
||||
@@ -1836,6 +1857,10 @@ describe('Project: legacy to SDK-style updates', function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should update legacy style project to SDK-style', async function (): Promise<void> {
|
||||
const projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||
const list: Uri[] = [];
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import * as should from 'should';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
@@ -49,11 +48,15 @@ describe('ProjectsController', function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
describe('project controller operations', function (): void {
|
||||
describe('Project file operations and prompting', function (): void {
|
||||
it('Should create new sqlproj file with correct values', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(testContext.outputChannel);
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
const projFileDir = path.join(testUtils.generateBaseFolderName(), `TestProject_${new Date().getTime()}`);
|
||||
|
||||
const projFilePath = await projController.createNewProject({
|
||||
newProjName: 'TestProjectName',
|
||||
@@ -70,7 +73,7 @@ describe('ProjectsController', function (): void {
|
||||
|
||||
it('Should create new sqlproj file with correct specified target platform', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(testContext.outputChannel);
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
const projFileDir = path.join(testUtils.generateBaseFolderName(), `TestProject_${new Date().getTime()}`);
|
||||
const projTargetPlatform = SqlTargetPlatform.sqlAzure; // default is SQL Server 2019
|
||||
|
||||
const projFilePath = await projController.createNewProject({
|
||||
@@ -447,6 +450,7 @@ describe('ProjectsController', function (): void {
|
||||
should(publishedDacpacPath).not.equal('', 'published dacpac path should be set');
|
||||
should(builtDacpacPath).not.equal(publishedDacpacPath, 'built and published dacpac paths should be different');
|
||||
should(postCopyContents).equal(fakeDacpacContents, 'contents of built and published dacpacs should match');
|
||||
await fs.rm(publishedDacpacPath);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,10 @@ describe('Publish profile tests', function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
after(async function(): Promise<void> {
|
||||
await testUtils.deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should read database name, integrated security connection string, and SQLCMD variables from publish profile', async function (): Promise<void> {
|
||||
await baselines.loadBaselines();
|
||||
const profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
|
||||
|
||||
@@ -13,6 +13,7 @@ import should = require('should');
|
||||
import { AssertionError } from 'assert';
|
||||
import { Project } from '../models/project';
|
||||
import { Uri } from 'vscode';
|
||||
import { exists } from '../common/utils';
|
||||
|
||||
export async function shouldThrowSpecificError(block: Function, expectedMessage: string, details?: string) {
|
||||
let succeeded = false;
|
||||
@@ -47,12 +48,17 @@ export async function createTestDataSources(contents: string, folderPath?: strin
|
||||
}
|
||||
|
||||
export async function generateTestFolderPath(): Promise<string> {
|
||||
const folderPath = path.join(os.tmpdir(), 'ADS_Tests', `TestRun_${new Date().getTime()}`);
|
||||
const folderPath = path.join(generateBaseFolderName(), `TestRun_${new Date().getTime()}`);
|
||||
await fs.mkdir(folderPath, { recursive: true });
|
||||
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
export function generateBaseFolderName(): string {
|
||||
const folderPath = path.join(os.tmpdir(), 'ADS_Tests');
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
export async function createTestFile(contents: string, fileName: string, folderPath?: string): Promise<string> {
|
||||
folderPath = folderPath ?? await generateTestFolderPath();
|
||||
const filePath = path.join(folderPath, fileName);
|
||||
@@ -249,3 +255,14 @@ export async function createOtherDummyFiles(testFolderPath: string): Promise<Uri
|
||||
|
||||
return filesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes folder generated for testing
|
||||
*/
|
||||
export async function deleteGeneratedTestFolder(): Promise<void> {
|
||||
const testFolderPath: string = generateBaseFolderName();
|
||||
if (await exists(testFolderPath)) {
|
||||
// cleanup folder
|
||||
await fs.rm(testFolderPath, { recursive: true });
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as should from 'should';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { createDummyFileStructure } from './testUtils';
|
||||
import { createDummyFileStructure, deleteGeneratedTestFolder } from './testUtils';
|
||||
import { exists, trimUri, removeSqlCmdVariableFormatting, formatSqlCmdVariable, isValidSqlCmdVariableName, timeConversion, validateSqlServerPortNumber, isEmptyString, detectCommandInstallation, isValidSQLPassword, findSqlVersionInImageName, findSqlVersionInTargetPlatform } from '../common/utils';
|
||||
import { Uri } from 'vscode';
|
||||
|
||||
@@ -20,6 +20,8 @@ describe('Tests to verify utils functions', function (): void {
|
||||
should(await exists(path.join(testFolderPath, 'folder4'))).equal(false);
|
||||
should(await exists(path.join(testFolderPath, 'folder2', 'file4.sql'))).equal(true);
|
||||
should(await exists(path.join(testFolderPath, 'folder4', 'file2.sql'))).equal(false);
|
||||
|
||||
await deleteGeneratedTestFolder();
|
||||
});
|
||||
|
||||
it('Should get correct relative paths of files/folders', async () => {
|
||||
|
||||
Reference in New Issue
Block a user