cleanup tests (#19732)

This commit is contained in:
Vasu Bhog
2022-06-15 11:08:49 -07:00
committed by GitHub
parent 909c56ffe3
commit 4d320c56f0
4 changed files with 49 additions and 49 deletions

View File

@@ -46,7 +46,7 @@ describe('AzureFunctionUtils', function (): void {
let writeFileStub = sinon.stub(fs.promises, 'writeFile');
await azureFunctionsUtils.setLocalAppSetting(path.dirname(localSettingsPath), 'test4', 'test4');
should(writeFileStub.calledWithExactly(localSettingsPath, `{\n "IsEncrypted": false,\n "Values": {\n "test1": "test1",\n "test2": "test2",\n "test3": "test3",\n "test4": "test4"\n }\n}`)).equals(true);
should(writeFileStub.calledWithExactly(localSettingsPath, `{\n "IsEncrypted": false,\n "Values": {\n "test1": "test1",\n "test2": "test2",\n "test3": "test3",\n "test4": "test4"\n }\n}`)).equals(true, 'writeFile should be called with the correct arguments');
});
it('Should not overwrite setting if value already exists in local.settings.json', async () => {
@@ -57,11 +57,11 @@ describe('AzureFunctionUtils', function (): void {
);
let warningMsg = constants.settingAlreadyExists('test1');
const spy = sinon.stub(vscode.window, 'showWarningMessage').resolves({ title: constants.settingAlreadyExists('test1') });
const showErrorMessageSpy = sinon.stub(vscode.window, 'showWarningMessage').resolves({ title: constants.settingAlreadyExists('test1') });
await azureFunctionsUtils.setLocalAppSetting(path.dirname(localSettingsPath), 'test1', 'newValue');
should(spy.calledOnce).be.true('showWarningMessage should have been called exactly once');
should(spy.calledWith(warningMsg)).be.true(`showWarningMessage not called with expected message '${warningMsg}' Actual '${spy.getCall(0).args[0]}'`);
should(showErrorMessageSpy.calledOnce).be.true('showWarningMessage should have been called exactly once');
should(showErrorMessageSpy.calledWith(warningMsg)).be.true(`showWarningMessage not called with expected message '${warningMsg}' Actual '${showErrorMessageSpy.getCall(0).args[0]}'`);
});
it('Should get settings file given project file', async () => {
@@ -79,7 +79,7 @@ describe('AzureFunctionUtils', function (): void {
let writeFileStub = sinon.stub(fs.promises, 'writeFile');
await azureFunctionsUtils.addConnectionStringToConfig(connectionString, rootFolderPath);
should(writeFileStub.calledWithExactly(localSettingsPath, `{\n "IsEncrypted": false,\n "Values": {\n "test1": "test1",\n "test2": "test2",\n "test3": "test3",\n "SqlConnectionString": "testConnectionString"\n }\n}`)).equals(true);
should(writeFileStub.calledWithExactly(localSettingsPath, `{\n "IsEncrypted": false,\n "Values": {\n "test1": "test1",\n "test2": "test2",\n "test3": "test3",\n "SqlConnectionString": "testConnectionString"\n }\n}`)).equals(true, 'writeFile should be called with the correct arguments');
});
});
@@ -93,7 +93,7 @@ describe('AzureFunctionUtils', function (): void {
testUtils.vscodeMssqlIExtension.setup(x => x.getConnectionString(connectionDetails, true, false)).returns(() => Promise.resolve(`Server=${connectionInfo.server};Initial Catalog=${connectionInfo.database};User ID=${connectionInfo.user};Password=${connectionInfo.password};`));
// Include Password Prompt - Yes to include password
let quickPickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().returns(Promise.resolve(constants.yesString) as any);
let quickPickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().resolves((constants.yesString) as any);
// Manually enter password
let quickInputSpy = sinon.spy(vscode.window, 'showInputBox');
// show warning window
@@ -106,7 +106,7 @@ describe('AzureFunctionUtils', function (): void {
should(quickInputSpy.notCalled).be.true('showInputBox should not have been called');
should(warningSpy.notCalled).be.true('showWarningMessage should not have been called');
// get connection string result
should(getConnectionString).equals(`Server=${connectionInfo.server};Initial Catalog=${connectionInfo.database};User ID=${connectionInfo.user};Password=${connectionInfo.password};`);
should(getConnectionString).equals(`Server=${connectionInfo.server};Initial Catalog=${connectionInfo.database};User ID=${connectionInfo.user};Password=${connectionInfo.password};`,'Should return a connection string with the password');
});
it('Should not include password and show warning if user does not want to include password prompt and connection info contains the password and auth type is SQL', async () => {
@@ -118,7 +118,7 @@ describe('AzureFunctionUtils', function (): void {
testUtils.vscodeMssqlIExtension.setup(x => x.getConnectionString(connectionDetails, false, false)).returns(() => Promise.resolve(`Server=${connectionInfo.server};Initial Catalog=${connectionInfo.database};User ID=${connectionInfo.user};Password=${constants.passwordPlaceholder};`));
// Include Password Prompt - NO to include password
let quickPickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().returns(Promise.resolve(constants.noString) as any);
let quickPickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().resolves((constants.noString) as any);
// Manually enter password
let quickInputSpy = sinon.spy(vscode.window, 'showInputBox');
// show warning window
@@ -131,7 +131,7 @@ describe('AzureFunctionUtils', function (): void {
should(quickInputSpy.notCalled).be.true('showInputBox should not have been called');
should(warningSpy.calledOnce).be.true('showWarningMessage should have been called');
// returned connection string should NOT include password
should(getConnectionString).equals(`Server=${connectionInfo.server};Initial Catalog=${connectionInfo.database};User ID=${connectionInfo.user};Password=${constants.passwordPlaceholder};`);
should(getConnectionString).equals(`Server=${connectionInfo.server};Initial Catalog=${connectionInfo.database};User ID=${connectionInfo.user};Password=${constants.passwordPlaceholder};`,'Should return a connection string without the password');
});
it('Should not include password and show warning if user cancels include password prompt and connection info contains the password and auth type is SQL', async () => {
@@ -268,7 +268,7 @@ describe('AzureFunctionUtils', function (): void {
// only one azure function project found - hostFiles and csproj files stubs
let findFilesStub = sinon.stub(vscode.workspace, 'findFiles');
findFilesStub.onFirstCall().resolves([vscode.Uri.file('/temp/host.json')]);
findFilesStub.onSecondCall().returns(Promise.resolve([vscode.Uri.file('/temp/test.csproj')]) as any);
findFilesStub.onSecondCall().resolves(([vscode.Uri.file('/temp/test.csproj')]) as any);
let result = await azureFunctionsUtils.getAzureFunctionProject();
should(result).be.equal('/temp/test.csproj', 'Should return test.csproj since only one Azure function project is found');
@@ -285,13 +285,13 @@ describe('AzureFunctionUtils', function (): void {
});
// multiple azure function projects found in workspace - hostFiles and project find files stubs
let findFilesStub = sinon.stub(vscode.workspace, 'findFiles');
findFilesStub.onFirstCall().returns(Promise.resolve([vscode.Uri.file('/temp/host.json'), vscode.Uri.file('/temp2/host.json')]) as any);
findFilesStub.onFirstCall().resolves(([vscode.Uri.file('/temp/host.json'), vscode.Uri.file('/temp2/host.json')]) as any);
// we loop through the hostFiles to find the csproj in same directory
// first loop we use host of /temp/host.json
findFilesStub.onSecondCall().returns(Promise.resolve([vscode.Uri.file('/temp/test.csproj')]) as any);
findFilesStub.onSecondCall().resolves(([vscode.Uri.file('/temp/test.csproj')]) as any);
// second loop we use host of /temp2/host.json
findFilesStub.onThirdCall().returns(Promise.resolve([vscode.Uri.file('/temp2/test.csproj')]) as any);
let quickPickStub = sinon.stub(vscode.window, 'showQuickPick').returns(Promise.resolve('/temp/test.csproj') as any);
findFilesStub.onThirdCall().resolves(([vscode.Uri.file('/temp2/test.csproj')]) as any);
let quickPickStub = sinon.stub(vscode.window, 'showQuickPick').resolves(('/temp/test.csproj') as any);
let result = await azureFunctionsUtils.getAzureFunctionProject();
should(result).be.equal('/temp/test.csproj', 'Should return test.csproj since user choose Azure function project');
@@ -345,7 +345,7 @@ describe('AzureFunctionUtils', function (): void {
testUtils.vscodeMssqlIExtension.setup(x => x.sendRequest(azureFunctionsContracts.SimpleExecuteRequest.type, params))
.returns(() => Promise.resolve({ rowCount: 1, columnInfo: [], rows: [['[schema].[testTable]']] }));
// select the schema.testTable from list of tables based on connection info and database
quickPickStub.onSecondCall().returns(Promise.resolve('[schema].[testTable]') as any);
quickPickStub.onSecondCall().resolves(('[schema].[testTable]') as any);
let result = await azureFunctionsUtils.promptForObjectName(BindingType.input, connectionInfo);