fix DefaultValue getting loaded for publish profiles (#17526)

* fix DefaultValue getting loaded for publish profiles

* add comment
This commit is contained in:
Kim Santiago
2021-11-02 11:32:25 -07:00
committed by GitHub
parent d7b0b6c251
commit 0d485ffe2b
6 changed files with 44 additions and 9 deletions

View File

@@ -31,7 +31,7 @@ describe('Publish profile tests', function (): void {
it('Should read database name, integrated security connection string, and SQLCMD variables from publish profile', async function (): Promise<void> {
await baselines.loadBaselines();
let profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
const profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
const connectionResult = {
connected: true,
connectionId: 'connId',
@@ -43,7 +43,7 @@ describe('Publish profile tests', function (): void {
});
sinon.stub(azdata.connection, 'connect').resolves(connectionResult);
let result = await load(vscode.Uri.file(profilePath), testContext.dacFxService.object);
const result = await load(vscode.Uri.file(profilePath), testContext.dacFxService.object);
should(result.databaseName).equal('targetDb');
should(Object.keys(result.sqlCmdVariables).length).equal(1);
should(result.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
@@ -54,7 +54,7 @@ describe('Publish profile tests', function (): void {
it('Should read database name, SQL login connection string, and SQLCMD variables from publish profile', async function (): Promise<void> {
await baselines.loadBaselines();
let profilePath = await testUtils.createTestFile(baselines.publishProfileSqlLoginBaseline, 'publishProfile.publish.xml');
const profilePath = await testUtils.createTestFile(baselines.publishProfileSqlLoginBaseline, 'publishProfile.publish.xml');
const connectionResult = {
providerName: 'MSSQL',
connectionId: 'connId',
@@ -68,7 +68,7 @@ describe('Publish profile tests', function (): void {
});
sinon.stub(azdata.connection, 'openConnectionDialog').resolves(connectionResult);
let result = await load(vscode.Uri.file(profilePath), testContext.dacFxService.object);
const result = await load(vscode.Uri.file(profilePath), testContext.dacFxService.object);
should(result.databaseName).equal('targetDb');
should(Object.keys(result.sqlCmdVariables).length).equal(1);
should(result.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
@@ -77,9 +77,23 @@ describe('Publish profile tests', function (): void {
should(result.options).equal(mockDacFxOptionsResult.deploymentOptions);
});
it('Should read SQLCMD variables correctly from publish profile even if DefaultValue is used', async function (): Promise<void> {
await baselines.loadBaselines();
const profilePath = await testUtils.createTestFile(baselines.publishProfileDefaultValueBaseline, 'publishProfile.publish.xml');
testContext.dacFxService.setup(x => x.getOptionsFromProfile(TypeMoq.It.isAny())).returns(async () => {
return Promise.resolve(mockDacFxOptionsResult);
});
const result = await load(vscode.Uri.file(profilePath), testContext.dacFxService.object);
should(Object.keys(result.sqlCmdVariables).length).equal(1);
// the profile has both Value and DefaultValue, but Value should be the one used
should(result.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
});
it('Should throw error when connecting does not work', async function (): Promise<void> {
await baselines.loadBaselines();
let profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
const profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
sinon.stub(azdata.connection, 'connect').throws(new Error('Could not connect'));