mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-25 22:30:29 -04:00
Alanren/integration test (#3657)
* add an extension for integration tests * setup ads before running test * test setup * test cases * bash script * shorter temp folder name * code cleanup * add commented out original code * fix test error * test result path * rename results file * change file path * report smoke test results * test stablize * test stablization and configurable test servers * fix smoke test error * connection provider * simplify the integration test script * add comment * fix tslint error * address PR comments * add temp log to check whether the environment variable is already set * remove temp log * move api definition to testapi typing file * exclude integration tests extension * address comments
This commit is contained in:
@@ -32,14 +32,16 @@ import { ConnectionStore } from 'sql/parts/connection/common/connectionStore';
|
||||
import { TestConnectionManagementService } from 'sqltest/stubs/connectionManagementService.test';
|
||||
import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { TestCommandService } from 'vs/editor/test/browser/editorTestServices';
|
||||
import { WorkspaceConfigurationTestService } from 'sqltest/stubs/workspaceConfigurationTestService';
|
||||
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
|
||||
|
||||
class TestParsedArgs implements ParsedArgs{
|
||||
class TestParsedArgs implements ParsedArgs {
|
||||
[arg: string]: any;
|
||||
_: string[];
|
||||
aad?: boolean;
|
||||
add?: boolean;
|
||||
database?:string;
|
||||
command?:string;
|
||||
database?: string;
|
||||
command?: string;
|
||||
debugBrkPluginHost?: string;
|
||||
debugBrkSearch?: string;
|
||||
debugId?: string;
|
||||
@@ -99,11 +101,11 @@ class TestParsedArgs implements ParsedArgs{
|
||||
suite('commandLineService tests', () => {
|
||||
|
||||
let capabilitiesService: CapabilitiesTestService;
|
||||
let commandLineService : CommandLineService;
|
||||
let environmentService : TypeMoq.Mock<EnvironmentService>;
|
||||
let queryEditorService : TypeMoq.Mock<QueryEditorService>;
|
||||
let editorService:TypeMoq.Mock<IEditorService>;
|
||||
let objectExplorerService : TypeMoq.Mock<ObjectExplorerService>;
|
||||
let commandLineService: CommandLineService;
|
||||
let environmentService: TypeMoq.Mock<EnvironmentService>;
|
||||
let queryEditorService: TypeMoq.Mock<QueryEditorService>;
|
||||
let editorService: TypeMoq.Mock<IEditorService>;
|
||||
let objectExplorerService: TypeMoq.Mock<ObjectExplorerService>;
|
||||
let connectionStore: TypeMoq.Mock<ConnectionStore>;
|
||||
|
||||
setup(() => {
|
||||
@@ -111,86 +113,112 @@ suite('commandLineService tests', () => {
|
||||
connectionStore = TypeMoq.Mock.ofType(ConnectionStore);
|
||||
});
|
||||
|
||||
function getCommandLineService(connectionManagementService : IConnectionManagementService,
|
||||
environmentService? : IEnvironmentService,
|
||||
capabilitiesService? : ICapabilitiesService,
|
||||
commandService? : ICommandService
|
||||
) : CommandLineService
|
||||
{
|
||||
let service= new CommandLineService(
|
||||
function getCommandLineService(connectionManagementService: IConnectionManagementService,
|
||||
configurationService: IWorkspaceConfigurationService,
|
||||
environmentService?: IEnvironmentService,
|
||||
capabilitiesService?: ICapabilitiesService,
|
||||
commandService?: ICommandService
|
||||
): CommandLineService {
|
||||
let service = new CommandLineService(
|
||||
connectionManagementService,
|
||||
capabilitiesService,
|
||||
environmentService,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
commandService
|
||||
commandService,
|
||||
configurationService
|
||||
);
|
||||
return service;
|
||||
}
|
||||
|
||||
function getConfigurationServiceMock(showConnectDialogOnStartup: boolean): TypeMoq.Mock<IWorkspaceConfigurationService> {
|
||||
let configurationService = TypeMoq.Mock.ofType<IWorkspaceConfigurationService>(WorkspaceConfigurationTestService);
|
||||
configurationService.setup((c) => c.getValue(TypeMoq.It.isAnyString())).returns((config: string) => showConnectDialogOnStartup);
|
||||
return configurationService;
|
||||
}
|
||||
|
||||
test('processCommandLine shows connection dialog by default', done => {
|
||||
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const connectionManagementService: TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
|
||||
connectionManagementService.setup((c) => c.showConnectionDialog())
|
||||
.returns(() => new Promise<void>((resolve, reject) => { resolve();}))
|
||||
.returns(() => new Promise<void>((resolve, reject) => { resolve(); }))
|
||||
.verifiable();
|
||||
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => false);
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused'); }))
|
||||
.verifiable(TypeMoq.Times.never());
|
||||
let service = getCommandLineService(connectionManagementService.object);
|
||||
service.processCommandLine().then( () => {
|
||||
const configurationService = getConfigurationServiceMock(true);
|
||||
let service = getCommandLineService(connectionManagementService.object, configurationService.object);
|
||||
service.processCommandLine().then(() => {
|
||||
connectionManagementService.verifyAll();
|
||||
done();
|
||||
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
}, error => { assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
});
|
||||
|
||||
test('processCommandLine does nothing if no server name and command name is provided and the configuration \'workbench.showConnectDialogOnStartup\' is set to false, even if registered servers exist', done => {
|
||||
const connectionManagementService: TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
|
||||
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
|
||||
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => false);
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
|
||||
.verifiable(TypeMoq.Times.never());
|
||||
const configurationService = getConfigurationServiceMock(false);
|
||||
let service = getCommandLineService(connectionManagementService.object, configurationService.object);
|
||||
|
||||
service.processCommandLine();
|
||||
connectionManagementService.verifyAll();
|
||||
done();
|
||||
});
|
||||
|
||||
test('processCommandLine does nothing if registered servers exist and no server name is provided', done => {
|
||||
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const connectionManagementService: TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
|
||||
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
|
||||
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true);
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused'); }))
|
||||
.verifiable(TypeMoq.Times.never());
|
||||
let service = getCommandLineService(connectionManagementService.object);
|
||||
service.processCommandLine().then( () => {
|
||||
const configurationService = getConfigurationServiceMock(true);
|
||||
let service = getCommandLineService(connectionManagementService.object, configurationService.object);
|
||||
service.processCommandLine().then(() => {
|
||||
connectionManagementService.verifyAll();
|
||||
done();
|
||||
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
}, error => { assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
});
|
||||
|
||||
test('processCommandLine opens a new connection if a server name is passed', done => {
|
||||
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const connectionManagementService: TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
|
||||
const environmentService : TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const args : TestParsedArgs = new TestParsedArgs();
|
||||
const environmentService: TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const args: TestParsedArgs = new TestParsedArgs();
|
||||
args.server = 'myserver';
|
||||
args.database = 'mydatabase';
|
||||
environmentService.setup(e => e.args).returns(() => args).verifiable(TypeMoq.Times.atLeastOnce());
|
||||
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
|
||||
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true).verifiable(TypeMoq.Times.atMostOnce());
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), 'connection', true))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused'); }))
|
||||
.verifiable(TypeMoq.Times.once());
|
||||
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService);
|
||||
service.processCommandLine().then( () => {
|
||||
const configurationService = getConfigurationServiceMock(true);
|
||||
let service = getCommandLineService(connectionManagementService.object, configurationService.object, environmentService.object, capabilitiesService);
|
||||
service.processCommandLine().then(() => {
|
||||
environmentService.verifyAll();
|
||||
connectionManagementService.verifyAll();
|
||||
done();
|
||||
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
}, error => { assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
});
|
||||
|
||||
test('processCommandLine invokes a command without a profile parameter when no server is passed', done => {
|
||||
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const environmentService : TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const commandService : TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
|
||||
const args : TestParsedArgs = new TestParsedArgs();
|
||||
const connectionManagementService: TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const environmentService: TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const commandService: TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
|
||||
const args: TestParsedArgs = new TestParsedArgs();
|
||||
|
||||
args.command = 'mycommand';
|
||||
environmentService.setup(e => e.args).returns(() => args);
|
||||
@@ -201,48 +229,50 @@ suite('commandLineService tests', () => {
|
||||
commandService.setup(c => c.executeCommand('mycommand'))
|
||||
.returns(() => TPromise.wrap(1))
|
||||
.verifiable(TypeMoq.Times.once());
|
||||
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService, commandService.object);
|
||||
service.processCommandLine().then( () => {
|
||||
const configurationService = getConfigurationServiceMock(true);
|
||||
let service = getCommandLineService(connectionManagementService.object, configurationService.object, environmentService.object, capabilitiesService, commandService.object);
|
||||
service.processCommandLine().then(() => {
|
||||
connectionManagementService.verifyAll();
|
||||
commandService.verifyAll();
|
||||
done();
|
||||
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
}, error => { assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
});
|
||||
|
||||
|
||||
test('processCommandLine invokes a command with a profile parameter when a server is passed', done => {
|
||||
|
||||
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const connectionManagementService: TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
|
||||
const environmentService : TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const commandService : TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
|
||||
const args : TestParsedArgs = new TestParsedArgs();
|
||||
const environmentService: TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const commandService: TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
|
||||
const args: TestParsedArgs = new TestParsedArgs();
|
||||
args.command = 'mycommand';
|
||||
args.server = 'myserver';
|
||||
environmentService.setup(e => e.args).returns(() => args);
|
||||
connectionManagementService.setup((c) => c.showConnectionDialog()).verifiable(TypeMoq.Times.never());
|
||||
connectionManagementService.setup(c => c.hasRegisteredServers()).returns(() => true).verifiable(TypeMoq.Times.atMostOnce());
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.is<ConnectionProfile>( p => p.serverName === 'myserver'), 'connection', true))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused');}))
|
||||
connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.is<ConnectionProfile>(p => p.serverName === 'myserver'), 'connection', true))
|
||||
.returns(() => new Promise<string>((resolve, reject) => { resolve('unused'); }))
|
||||
.verifiable(TypeMoq.Times.once());
|
||||
commandService.setup(c => c.executeCommand('mycommand', TypeMoq.It.is<ConnectionProfile>( p => p.serverName === 'myserver')))
|
||||
commandService.setup(c => c.executeCommand('mycommand', TypeMoq.It.is<ConnectionProfile>(p => p.serverName === 'myserver')))
|
||||
.returns(() => TPromise.wrap(1))
|
||||
.verifiable(TypeMoq.Times.once());
|
||||
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService, commandService.object);
|
||||
service.processCommandLine().then( () => {
|
||||
const configurationService = getConfigurationServiceMock(true);
|
||||
let service = getCommandLineService(connectionManagementService.object, configurationService.object, environmentService.object, capabilitiesService, commandService.object);
|
||||
service.processCommandLine().then(() => {
|
||||
connectionManagementService.verifyAll();
|
||||
commandService.verifyAll();
|
||||
done();
|
||||
}, error => {assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
}, error => { assert.fail(error, null, 'processCommandLine rejected ' + error); done(); });
|
||||
});
|
||||
|
||||
test('processCommandLine rejects unknown commands', done => {
|
||||
const connectionManagementService : TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const environmentService : TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const commandService : TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
|
||||
const args : TestParsedArgs = new TestParsedArgs();
|
||||
const connectionManagementService: TypeMoq.Mock<IConnectionManagementService>
|
||||
= TypeMoq.Mock.ofType<IConnectionManagementService>(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
|
||||
const environmentService: TypeMoq.Mock<IEnvironmentService> = TypeMoq.Mock.ofType<IEnvironmentService>(EnvironmentService);
|
||||
const commandService: TypeMoq.Mock<ICommandService> = TypeMoq.Mock.ofType<ICommandService>(TestCommandService);
|
||||
const args: TestParsedArgs = new TestParsedArgs();
|
||||
|
||||
args.command = 'mycommand';
|
||||
environmentService.setup(e => e.args).returns(() => args);
|
||||
@@ -250,9 +280,10 @@ suite('commandLineService tests', () => {
|
||||
commandService.setup(c => c.executeCommand('mycommand'))
|
||||
.returns(() => TPromise.wrapError(new Error('myerror')))
|
||||
.verifiable(TypeMoq.Times.once());
|
||||
let service = getCommandLineService(connectionManagementService.object, environmentService.object, capabilitiesService, commandService.object);
|
||||
service.processCommandLine().then( () => {
|
||||
assert.fail(1,null, 'processCommandLine should reject when executeCommand errors out');
|
||||
const configurationService = getConfigurationServiceMock(true);
|
||||
let service = getCommandLineService(connectionManagementService.object, configurationService.object, environmentService.object, capabilitiesService, commandService.object);
|
||||
service.processCommandLine().then(() => {
|
||||
assert.fail(1, null, 'processCommandLine should reject when executeCommand errors out');
|
||||
done();
|
||||
}, error => {
|
||||
assert.equal(error.message, 'myerror', 'unexpected error from processCommandLine ' + error);
|
||||
|
||||
Reference in New Issue
Block a user