mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 17:52:34 -05:00
Add static logger class for azdata extension (#11939)
* Add static logger class for arc extension * Fix compile errors * Fix test
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as azdata from '../azdata';
|
||||
import * as sinon from 'sinon';
|
||||
import * as childProcess from '../common/childProcess';
|
||||
@@ -14,11 +12,6 @@ import * as nock from 'nock';
|
||||
|
||||
describe('azdata', function () {
|
||||
|
||||
let outputChannelMock: TypeMoq.IMock<vscode.OutputChannel>;
|
||||
beforeEach(function (): void {
|
||||
outputChannelMock = TypeMoq.Mock.ofType<vscode.OutputChannel>();
|
||||
|
||||
});
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
nock.cleanAll();
|
||||
@@ -33,7 +26,7 @@ describe('azdata', function () {
|
||||
}
|
||||
// Mock call to --version to simulate azdata being installed
|
||||
sinon.stub(childProcess, 'executeCommand').returns(Promise.resolve({ stdout: 'v1.0.0', stderr: '' }));
|
||||
await should(azdata.findAzdata(outputChannelMock.object)).not.be.rejected();
|
||||
await should(azdata.findAzdata()).not.be.rejected();
|
||||
});
|
||||
it('unsuccessful', async function (): Promise<void> {
|
||||
if (process.platform === 'win32') {
|
||||
@@ -43,7 +36,7 @@ describe('azdata', function () {
|
||||
// Mock call to executeCommand to simulate azdata --version returning error
|
||||
sinon.stub(childProcess, 'executeCommand').returns(Promise.reject({ stdout: '', stderr: 'command not found: azdata' }));
|
||||
}
|
||||
await should(azdata.findAzdata(outputChannelMock.object)).be.rejected();
|
||||
await should(azdata.findAzdata()).be.rejected();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,7 +50,7 @@ describe('azdata', function () {
|
||||
nock(azdata.azdataHostname)
|
||||
.get(`/${azdata.azdataUri}`)
|
||||
.replyWithFile(200, __filename);
|
||||
const downloadPromise = azdata.downloadAndInstallAzdata(outputChannelMock.object);
|
||||
const downloadPromise = azdata.downloadAndInstallAzdata();
|
||||
await downloadPromise;
|
||||
});
|
||||
|
||||
@@ -65,7 +58,7 @@ describe('azdata', function () {
|
||||
nock('https://aka.ms')
|
||||
.get('/azdata-msi')
|
||||
.reply(404);
|
||||
const downloadPromise = azdata.downloadAndInstallAzdata(outputChannelMock.object);
|
||||
const downloadPromise = azdata.downloadAndInstallAzdata();
|
||||
await should(downloadPromise).be.rejected();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,16 +3,14 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as should from 'should';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sudo from 'sudo-prompt';
|
||||
import * as sinon from 'sinon';
|
||||
import Logger from '../../common/logger';
|
||||
|
||||
import { executeCommand, executeSudoCommand } from '../../common/childProcess';
|
||||
|
||||
describe('ChildProcess', function (): void {
|
||||
const outputChannelMock = TypeMoq.Mock.ofType<vscode.OutputChannel>();
|
||||
|
||||
afterEach(function(): void {
|
||||
sinon.restore();
|
||||
@@ -21,19 +19,20 @@ describe('ChildProcess', function (): void {
|
||||
describe('executeCommand', function(): void {
|
||||
[[], ['test']].forEach(args => {
|
||||
it(`Output channel is used with ${JSON.stringify(args)} args`, async function (): Promise<void> {
|
||||
await executeCommand('echo', args, outputChannelMock.object);
|
||||
outputChannelMock.verify(x => x.appendLine(TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
|
||||
const logStub = sinon.stub(Logger, 'log');
|
||||
await executeCommand('echo', args);
|
||||
should(logStub.called).be.true('Log should have been called');
|
||||
});
|
||||
});
|
||||
|
||||
it('Gets expected output', async function (): Promise<void> {
|
||||
const echoOutput = 'test';
|
||||
const output = await executeCommand('echo', [echoOutput], outputChannelMock.object);
|
||||
const output = await executeCommand('echo', [echoOutput]);
|
||||
should(output.stdout).equal(echoOutput);
|
||||
});
|
||||
|
||||
it('Invalid command errors', async function (): Promise<void> {
|
||||
await should(executeCommand('invalid_command', [], outputChannelMock.object)).be.rejected();
|
||||
await should(executeCommand('invalid_command', [])).be.rejected();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,7 +42,7 @@ describe('ChildProcess', function (): void {
|
||||
sinon.stub(sudo, 'exec').callsFake( (_cmd, _options, callback) => {
|
||||
callback!(undefined, stdout);
|
||||
});
|
||||
const result = await executeSudoCommand('echo', outputChannelMock.object);
|
||||
const result = await executeSudoCommand('echo');
|
||||
should(result.stdout).equal(stdout);
|
||||
should(result.stderr).equal('');
|
||||
});
|
||||
@@ -53,7 +52,7 @@ describe('ChildProcess', function (): void {
|
||||
sinon.stub(sudo, 'exec').callsFake( (_cmd, _options, callback) => {
|
||||
callback!(undefined, undefined, stderr);
|
||||
});
|
||||
const result = await executeSudoCommand('echo', outputChannelMock.object);
|
||||
const result = await executeSudoCommand('echo');
|
||||
should(result.stdout).equal('');
|
||||
should(result.stderr).equal(stderr);
|
||||
});
|
||||
@@ -62,7 +61,7 @@ describe('ChildProcess', function (): void {
|
||||
sinon.stub(sudo, 'exec').callsFake( (_cmd, _options, callback) => {
|
||||
callback!(new Error('error'));
|
||||
});
|
||||
await should(executeSudoCommand('invalid_command', outputChannelMock.object)).be.rejected();
|
||||
await should(executeSudoCommand('invalid_command')).be.rejected();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as should from 'should';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { HttpClient } from '../../common/httpClient';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
@@ -16,12 +14,6 @@ import { Deferred } from '../../common/promise';
|
||||
|
||||
describe('HttpClient', function (): void {
|
||||
|
||||
let outputChannelMock: TypeMoq.IMock<vscode.OutputChannel>;
|
||||
|
||||
before(function (): void {
|
||||
outputChannelMock = TypeMoq.Mock.ofType<vscode.OutputChannel>();
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
nock.cleanAll();
|
||||
nock.enableNetConnect();
|
||||
@@ -33,7 +25,7 @@ describe('HttpClient', function (): void {
|
||||
.get('/README.md')
|
||||
.replyWithFile(200, __filename);
|
||||
const downloadFolder = os.tmpdir();
|
||||
const downloadPath = await HttpClient.download('https://127.0.0.1/README.md', downloadFolder, outputChannelMock.object);
|
||||
const downloadPath = await HttpClient.download('https://127.0.0.1/README.md', downloadFolder);
|
||||
// Verify file was downloaded correctly
|
||||
await fs.promises.stat(downloadPath);
|
||||
});
|
||||
@@ -43,7 +35,7 @@ describe('HttpClient', function (): void {
|
||||
nock('https://127.0.0.1')
|
||||
.get('/')
|
||||
.replyWithError('Unexpected Error');
|
||||
const downloadPromise = HttpClient.download('https://127.0.0.1', downloadFolder, outputChannelMock.object);
|
||||
const downloadPromise = HttpClient.download('https://127.0.0.1', downloadFolder);
|
||||
|
||||
await should(downloadPromise).be.rejected();
|
||||
});
|
||||
@@ -53,7 +45,7 @@ describe('HttpClient', function (): void {
|
||||
nock('https://127.0.0.1')
|
||||
.get('/')
|
||||
.reply(404, '');
|
||||
const downloadPromise = HttpClient.download('https://127.0.0.1', downloadFolder, outputChannelMock.object);
|
||||
const downloadPromise = HttpClient.download('https://127.0.0.1', downloadFolder);
|
||||
|
||||
await should(downloadPromise).be.rejected();
|
||||
});
|
||||
@@ -69,7 +61,7 @@ describe('HttpClient', function (): void {
|
||||
nock('https://127.0.0.1')
|
||||
.get('/')
|
||||
.reply(200, '');
|
||||
const downloadPromise = HttpClient.download('https://127.0.0.1', downloadFolder, outputChannelMock.object);
|
||||
const downloadPromise = HttpClient.download('https://127.0.0.1', downloadFolder);
|
||||
// Wait for the stream to be created before throwing the error or HttpClient will miss the event
|
||||
await deferredPromise;
|
||||
try {
|
||||
@@ -87,7 +79,7 @@ describe('HttpClient', function (): void {
|
||||
nock('https://127.0.0.1')
|
||||
.get(`/${filename}`)
|
||||
.reply(200);
|
||||
const receivedFilename = await HttpClient.getFilename(`https://127.0.0.1/${filename}`, outputChannelMock.object);
|
||||
const receivedFilename = await HttpClient.getFilename(`https://127.0.0.1/${filename}`);
|
||||
|
||||
should(receivedFilename).equal(filename);
|
||||
});
|
||||
@@ -96,7 +88,7 @@ describe('HttpClient', function (): void {
|
||||
nock('https://127.0.0.1')
|
||||
.get('/')
|
||||
.replyWithError('Unexpected Error');
|
||||
const getFilenamePromise = HttpClient.getFilename('https://127.0.0.1', outputChannelMock.object);
|
||||
const getFilenamePromise = HttpClient.getFilename('https://127.0.0.1');
|
||||
|
||||
await should(getFilenamePromise).be.rejected();
|
||||
});
|
||||
@@ -105,7 +97,7 @@ describe('HttpClient', function (): void {
|
||||
nock('https://127.0.0.1')
|
||||
.get('/')
|
||||
.reply(404, '');
|
||||
const getFilenamePromise = HttpClient.getFilename('https://127.0.0.1', outputChannelMock.object);
|
||||
const getFilenamePromise = HttpClient.getFilename('https://127.0.0.1');
|
||||
|
||||
await should(getFilenamePromise).be.rejected();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user