mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add azdata tests (#11745)
This commit is contained in:
@@ -48,8 +48,12 @@ describe('azdata', function () {
|
||||
});
|
||||
|
||||
// TODO: Install not implemented on linux yet
|
||||
describe.skip('downloadAndInstallAzdata', function (): void {
|
||||
describe('downloadAndInstallAzdata', function (): void {
|
||||
it('successful download & install', async function (): Promise<void> {
|
||||
sinon.stub(childProcess, 'executeCommand').returns(Promise.resolve({ stdout: '', stderr: '' }));
|
||||
if (process.platform === 'linux') {
|
||||
sinon.stub(childProcess, 'executeSudoCommand').returns(Promise.resolve({ stdout: '', stderr: '' }));
|
||||
}
|
||||
nock(azdata.azdataHostname)
|
||||
.get(`/${azdata.azdataUri}`)
|
||||
.replyWithFile(200, __filename);
|
||||
|
||||
@@ -6,25 +6,64 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as should from 'should';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { executeCommand } from '../../common/childProcess';
|
||||
import * as sudo from 'sudo-prompt';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
describe('ChildProcess', function () {
|
||||
import { executeCommand, executeSudoCommand } from '../../common/childProcess';
|
||||
|
||||
describe('ChildProcess', function (): void {
|
||||
const outputChannelMock = TypeMoq.Mock.ofType<vscode.OutputChannel>();
|
||||
|
||||
[[], ['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());
|
||||
afterEach(function(): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
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());
|
||||
});
|
||||
});
|
||||
|
||||
it('Gets expected output', async function (): Promise<void> {
|
||||
const echoOutput = 'test';
|
||||
const output = await executeCommand('echo', [echoOutput], outputChannelMock.object);
|
||||
should(output.stdout).equal(echoOutput);
|
||||
});
|
||||
|
||||
it('Invalid command errors', async function (): Promise<void> {
|
||||
await should(executeCommand('invalid_command', [], outputChannelMock.object)).be.rejected();
|
||||
});
|
||||
});
|
||||
|
||||
it('Gets expected output', async function (): Promise<void> {
|
||||
const echoOutput = 'test';
|
||||
const output = await executeCommand('echo', [echoOutput], outputChannelMock.object);
|
||||
should(output.stdout).equal(echoOutput);
|
||||
describe('executeSudoCommand', function(): void {
|
||||
it('Gets expected stdout output', async function (): Promise<void> {
|
||||
const stdout = 'stdout output';
|
||||
sinon.stub(sudo, 'exec').callsFake( (_cmd, _options, callback) => {
|
||||
callback!(undefined, stdout);
|
||||
});
|
||||
const result = await executeSudoCommand('echo', outputChannelMock.object);
|
||||
should(result.stdout).equal(stdout);
|
||||
should(result.stderr).equal('');
|
||||
});
|
||||
|
||||
it('Gets expected stderr output', async function (): Promise<void> {
|
||||
const stderr = 'stderr output';
|
||||
sinon.stub(sudo, 'exec').callsFake( (_cmd, _options, callback) => {
|
||||
callback!(undefined, undefined, stderr);
|
||||
});
|
||||
const result = await executeSudoCommand('echo', outputChannelMock.object);
|
||||
should(result.stdout).equal('');
|
||||
should(result.stderr).equal(stderr);
|
||||
});
|
||||
|
||||
it('Error rejects', async function (): Promise<void> {
|
||||
sinon.stub(sudo, 'exec').callsFake( (_cmd, _options, callback) => {
|
||||
callback!(new Error('error'));
|
||||
});
|
||||
await should(executeSudoCommand('invalid_command', outputChannelMock.object)).be.rejected();
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid command errors', async function (): Promise<void> {
|
||||
await should(executeCommand('invalid_command', [], outputChannelMock.object)).be.rejected();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user