mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 01:25:36 -05:00
Database projects deploy (#10417)
* Hooking up deployment of SQL projects to the project build functionality and database selection UI * Adding ADS-side plumbing for sqlcmdvars
This commit is contained in:
@@ -22,9 +22,9 @@ describe('Data Sources: DataSource operations', function (): void {
|
||||
|
||||
should(dataSourceList[0].name).equal('Test Data Source 1');
|
||||
should(dataSourceList[0].type).equal(sql.SqlConnectionDataSource.type);
|
||||
should((dataSourceList[0] as sql.SqlConnectionDataSource).getSetting('Initial Catalog')).equal('testDb');
|
||||
should((dataSourceList[0] as sql.SqlConnectionDataSource).database).equal('testDb');
|
||||
|
||||
should(dataSourceList[1].name).equal('My Other Data Source');
|
||||
should((dataSourceList[1] as sql.SqlConnectionDataSource).getSetting('Integrated Security')).equal('False');
|
||||
should((dataSourceList[1] as sql.SqlConnectionDataSource).integratedSecurity).equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('Project: sqlproj content operations', function (): void {
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
projFilePath = await testUtils.createTestSqlProj(baselines.openProjectFileBaseline);
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline);
|
||||
});
|
||||
|
||||
it('Should read Project from sqlproj', async function (): Promise<void> {
|
||||
|
||||
@@ -17,6 +17,9 @@ import { ProjectsController } from '../controllers/projectController';
|
||||
import { promises as fs } from 'fs';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
import { Project } from '../models/project';
|
||||
import { DeployDatabaseDialog } from '../dialogs/deployDatabaseDialog';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { IDeploymentProfile, IGenerateScriptProfile } from '../models/IDeploymentProfile';
|
||||
|
||||
let testContext: TestContext;
|
||||
|
||||
@@ -27,43 +30,99 @@ describe('ProjectsController: project controller operations', function (): void
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
it('Should create new sqlproj file with correct values', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
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.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
|
||||
const projFilePath = await projController.createNewProject('TestProjectName', vscode.Uri.file(projFileDir), 'BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575');
|
||||
const projFilePath = await projController.createNewProject('TestProjectName', vscode.Uri.file(projFileDir), 'BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575');
|
||||
|
||||
let projFileText = (await fs.readFile(projFilePath)).toString();
|
||||
let projFileText = (await fs.readFile(projFilePath)).toString();
|
||||
|
||||
should(projFileText).equal(baselines.newProjectFileBaseline);
|
||||
});
|
||||
should(projFileText).equal(baselines.newProjectFileBaseline);
|
||||
});
|
||||
|
||||
it('Should load Project and associated DataSources', async function (): Promise<void> {
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProj(baselines.openProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
|
||||
should(project.files.length).equal(9); // detailed sqlproj tests in their own test file
|
||||
should(project.dataSources.length).equal(2); // detailed datasources tests in their own test file
|
||||
});
|
||||
|
||||
it('Should return silently when no object name provided', async function (): Promise<void> {
|
||||
for (const name of ['', ' ', undefined]) {
|
||||
testContext.apiWrapper.reset();
|
||||
testContext.apiWrapper.setup(x => x.showInputBox(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(name));
|
||||
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { console.log('we throwin'); throw new Error(s); });
|
||||
it('Should load Project and associated DataSources', async function (): Promise<void> {
|
||||
// setup test files
|
||||
const folderPath = await testUtils.generateTestFolderPath();
|
||||
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline, folderPath);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||
|
||||
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||
const project = new Project('FakePath');
|
||||
|
||||
should(project.files.length).equal(0);
|
||||
await projController.addItemPrompt(new Project('FakePath'), '', templates.script);
|
||||
should(project.files.length).equal(0, 'Expected to return without throwing an exception or adding a file when an empty/undefined name is provided.');
|
||||
}
|
||||
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||
|
||||
should(project.files.length).equal(9); // detailed sqlproj tests in their own test file
|
||||
should(project.dataSources.length).equal(2); // detailed datasources tests in their own test file
|
||||
});
|
||||
|
||||
it('Should return silently when no SQL object name provided in prompts', async function (): Promise<void> {
|
||||
for (const name of ['', ' ', undefined]) {
|
||||
testContext.apiWrapper.reset();
|
||||
testContext.apiWrapper.setup(x => x.showInputBox(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(name));
|
||||
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
|
||||
|
||||
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||
const project = new Project('FakePath');
|
||||
|
||||
should(project.files.length).equal(0);
|
||||
await projController.addItemPrompt(new Project('FakePath'), '', templates.script);
|
||||
should(project.files.length).equal(0, 'Expected to return without throwing an exception or adding a file when an empty/undefined name is provided.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Deployment and deployment script generation', function (): void {
|
||||
it('Deploy dialog should open from ProjectController', async function (): Promise<void> {
|
||||
let opened = false;
|
||||
|
||||
let deployDialog = TypeMoq.Mock.ofType(DeployDatabaseDialog);
|
||||
deployDialog.setup(x => x.openDialog()).returns(() => { opened = true; });
|
||||
|
||||
let projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||
projController.callBase = true;
|
||||
projController.setup(x => x.getDeployDialog(TypeMoq.It.isAny())).returns(() => deployDialog.object);
|
||||
|
||||
await projController.object.deployProject(new Project('FakePath'));
|
||||
should(opened).equal(true);
|
||||
});
|
||||
|
||||
it('Callbacks are hooked up and called from Deploy dialog', async function (): Promise<void> {
|
||||
const projPath = path.dirname(await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline));
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, projPath);
|
||||
const proj = new Project(projPath);
|
||||
|
||||
const deployHoller = 'hello from callback for deploy()';
|
||||
const generateHoller = 'hello from callback for generateScript()';
|
||||
|
||||
let holler = 'nothing';
|
||||
|
||||
let deployDialog = TypeMoq.Mock.ofType(DeployDatabaseDialog, undefined, undefined, new ApiWrapper(), proj);
|
||||
deployDialog.callBase = true;
|
||||
deployDialog.setup(x => x.getConnectionUri()).returns(async () => 'fake|connection|uri');
|
||||
|
||||
let projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||
projController.callBase = true;
|
||||
projController.setup(x => x.getDeployDialog(TypeMoq.It.isAny())).returns(() => deployDialog.object);
|
||||
projController.setup(x => x.executionCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IDeploymentProfile => true))).returns(async () => {
|
||||
holler = deployHoller;
|
||||
return undefined;
|
||||
});
|
||||
|
||||
projController.setup(x => x.executionCallback(TypeMoq.It.isAny(), TypeMoq.It.is((_): _ is IGenerateScriptProfile => true))).returns(async () => {
|
||||
holler = generateHoller;
|
||||
return undefined;
|
||||
});
|
||||
|
||||
let dialog = await projController.object.deployProject(proj);
|
||||
await dialog.deployClick();
|
||||
|
||||
should(holler).equal(deployHoller, 'executionCallback() is supposed to have been setup and called for Deploy scenario');
|
||||
|
||||
dialog = await projController.object.deployProject(proj);
|
||||
await dialog.generateScriptClick();
|
||||
|
||||
should(holler).equal(generateHoller, 'executionCallback() is supposed to have been setup and called for GenerateScript scenario');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ import * as constants from '../common/constants';
|
||||
import { promises as fs } from 'fs';
|
||||
import should = require('should');
|
||||
import { AssertionError } from 'assert';
|
||||
import { Project } from '../models/project';
|
||||
|
||||
export async function shouldThrowSpecificError(block: Function, expectedMessage: string, details?: string) {
|
||||
let succeeded = false;
|
||||
@@ -26,10 +27,14 @@ export async function shouldThrowSpecificError(block: Function, expectedMessage:
|
||||
}
|
||||
}
|
||||
|
||||
export async function createTestSqlProj(contents: string, folderPath?: string): Promise<string> {
|
||||
export async function createTestSqlProjFile(contents: string, folderPath?: string): Promise<string> {
|
||||
return await createTestFile(contents, 'TestProject.sqlproj', folderPath);
|
||||
}
|
||||
|
||||
export async function createTestProject(contents: string, folderPath?: string): Promise<Project> {
|
||||
return new Project(await createTestSqlProjFile(contents, folderPath));
|
||||
}
|
||||
|
||||
export async function createTestDataSources(contents: string, folderPath?: string): Promise<string> {
|
||||
return await createTestFile(contents, constants.dataSourcesFileName, folderPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user