mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-30 01:25:38 -05:00
Move code around for more linting (#8190)
* testing * moving around all the code * fix strict nulls
This commit is contained in:
@@ -9,8 +9,8 @@ import * as azdata from 'azdata';
|
||||
import * as assert from 'assert';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
|
||||
suite('SQL ConnectionProfileInfo tests', () => {
|
||||
let msSQLCapabilities: ConnectionProviderProperties;
|
||||
|
||||
@@ -1,258 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as azdata from 'azdata';
|
||||
import { ConnectionStatusManager } from 'sql/platform/connection/common/connectionStatusManager';
|
||||
import * as Utils from 'sql/platform/connection/common/utils';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { TestEnvironmentService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
|
||||
let connections: ConnectionStatusManager;
|
||||
let capabilitiesService: TestCapabilitiesService;
|
||||
let connectionProfileObject: ConnectionProfile;
|
||||
let connectionProfile: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection1',
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
let editorConnectionProfile: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection2',
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
let connectionProfileWithoutDbName: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: '',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection1',
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
|
||||
let connection1Id: string;
|
||||
let connection2Id: string;
|
||||
let connection3Id: string;
|
||||
|
||||
suite('SQL ConnectionStatusManager tests', () => {
|
||||
setup(() => {
|
||||
capabilitiesService = new TestCapabilitiesService();
|
||||
connectionProfileObject = new ConnectionProfile(capabilitiesService, connectionProfile);
|
||||
connections = new ConnectionStatusManager(capabilitiesService, new NullLogService(), TestEnvironmentService, new TestNotificationService());
|
||||
connection1Id = Utils.generateUri(connectionProfile);
|
||||
connection2Id = 'connection2Id';
|
||||
connection3Id = 'connection3Id';
|
||||
connections.addConnection(connectionProfile, connection1Id);
|
||||
connections.addConnection(editorConnectionProfile, connection2Id);
|
||||
connections.addConnection(connectionProfileWithoutDbName, connection3Id);
|
||||
});
|
||||
|
||||
test('findConnection should return undefined given invalid id', () => {
|
||||
let id: string = 'invalid id';
|
||||
let expected = undefined;
|
||||
let actual = connections.findConnection(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('findConnection should return connection given valid id', () => {
|
||||
let id: string = connection1Id;
|
||||
let expected = connectionProfileObject;
|
||||
let actual = connections.findConnection(id);
|
||||
assert.equal(connectionProfileObject.matches(actual.connectionProfile), true);
|
||||
});
|
||||
|
||||
test('getConnectionProfile should return undefined given invalid id', () => {
|
||||
let id: string = 'invalid id';
|
||||
let expected = undefined;
|
||||
let actual = connections.getConnectionProfile(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('getConnectionProfile should return connection given valid id', () => {
|
||||
let id: string = connection1Id;
|
||||
let expected = connectionProfileObject;
|
||||
let actual = connections.getConnectionProfile(id);
|
||||
assert.equal(connectionProfileObject.matches(actual), true);
|
||||
});
|
||||
|
||||
test('hasConnection should return false given invalid id', () => {
|
||||
let id: string = 'invalid id';
|
||||
let expected = false;
|
||||
let actual = connections.hasConnection(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('hasConnection should return true given valid id', () => {
|
||||
let id: string = connection1Id;
|
||||
let expected = true;
|
||||
let actual = connections.hasConnection(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('addConnection should set connecting to true', () => {
|
||||
let expected = true;
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
ownerUri: connection1Id,
|
||||
connectionId: connection1Id,
|
||||
messages: undefined,
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
serverInfo: undefined,
|
||||
connectionSummary: undefined
|
||||
};
|
||||
connections.onConnectionComplete(summary);
|
||||
let actual = connections.addConnection(connectionProfile, connection1Id).connecting;
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('onConnectionComplete should set connecting to false', () => {
|
||||
let expected = false;
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
ownerUri: connection1Id,
|
||||
connectionId: connection1Id,
|
||||
messages: undefined,
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
serverInfo: undefined,
|
||||
connectionSummary: undefined
|
||||
};
|
||||
connections.onConnectionComplete(summary);
|
||||
let actual = connections.findConnection(connection1Id).connecting;
|
||||
assert.equal(actual, expected);
|
||||
actual = connections.isConnecting(connection1Id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('updateConnection should update the connection info', () => {
|
||||
let expected = connectionProfile.groupId + '1';
|
||||
let expectedConnectionId = 'new id';
|
||||
connections.addConnection(connectionProfile, connection1Id);
|
||||
|
||||
let updatedConnection = Object.assign({}, connectionProfile, { groupId: expected, getOptionsKey: () => connectionProfile.getOptionsKey() + expected, id: expectedConnectionId });
|
||||
let actualId = connections.updateConnectionProfile(updatedConnection, connection1Id);
|
||||
|
||||
let newId = Utils.generateUri(updatedConnection);
|
||||
let actual = connections.getConnectionProfile(newId).groupId;
|
||||
let actualConnectionId = connections.getConnectionProfile(newId).id;
|
||||
assert.equal(actual, expected);
|
||||
assert.equal(actualId, newId);
|
||||
assert.equal(actualConnectionId, expectedConnectionId);
|
||||
});
|
||||
|
||||
test('updateDatabaseName should update the database name in connection', () => {
|
||||
let dbName: string = 'db name';
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
connectionSummary: {
|
||||
databaseName: dbName,
|
||||
serverName: undefined,
|
||||
userName: undefined
|
||||
}
|
||||
, ownerUri: connection3Id,
|
||||
connectionId: 'connection id',
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
messages: undefined,
|
||||
serverInfo: undefined
|
||||
};
|
||||
|
||||
//The original connection didn't have database name
|
||||
let connectionStatus = connections.findConnection(connection3Id);
|
||||
connectionStatus.connectionProfile.databaseName = '';
|
||||
|
||||
//Verify database name changed after connection is complete
|
||||
connections.updateDatabaseName(summary);
|
||||
connectionStatus = connections.findConnection(connection3Id);
|
||||
assert.equal(connectionStatus.connectionProfile.databaseName, dbName);
|
||||
});
|
||||
|
||||
test('getOriginalOwnerUri should return the original uri given uri with db name', () => {
|
||||
let dbName: string = 'db name';
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
connectionSummary: {
|
||||
databaseName: dbName,
|
||||
serverName: undefined,
|
||||
userName: undefined
|
||||
}
|
||||
, ownerUri: connection3Id,
|
||||
connectionId: 'connection id',
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
messages: undefined,
|
||||
serverInfo: undefined
|
||||
};
|
||||
|
||||
//The original connection didn't have database name
|
||||
let connectionStatus = connections.findConnection(connection3Id);
|
||||
connectionStatus.connectionProfile.databaseName = '';
|
||||
|
||||
//Verify database name changed after connection is complete
|
||||
connections.updateDatabaseName(summary);
|
||||
connectionStatus = connections.findConnection(connection3Id);
|
||||
let ownerUriWithDbName = Utils.generateUriWithPrefix(connectionStatus.connectionProfile, 'connection:');
|
||||
|
||||
//The uri assigned to connection without db name should be the original one
|
||||
let connectionWitDbStatus = connections.getOriginalOwnerUri(ownerUriWithDbName);
|
||||
assert.equal(connectionWitDbStatus, connection3Id);
|
||||
});
|
||||
|
||||
test('getOriginalOwnerUri should return given uri if the original uri is the same as the given uri', () => {
|
||||
|
||||
let connectionStatus = connections.getOriginalOwnerUri(connection2Id);
|
||||
assert.equal(connectionStatus, connection2Id);
|
||||
});
|
||||
|
||||
test('getActiveConnectionProfiles should return a list of all the unique connections that the status manager knows about', () => {
|
||||
// Add duplicate connections
|
||||
let newConnection = Object.assign({}, connectionProfile);
|
||||
newConnection.id = 'test_id';
|
||||
newConnection.serverName = 'new_server_name';
|
||||
newConnection.options['databaseDisplayName'] = newConnection.databaseName;
|
||||
connections.addConnection(newConnection, 'test_uri_1');
|
||||
connections.addConnection(newConnection, 'test_uri_2');
|
||||
|
||||
// Get the connections and verify that the duplicate is only returned once
|
||||
let activeConnections = connections.getActiveConnectionProfiles();
|
||||
assert.equal(activeConnections.length, 4);
|
||||
assert.equal(activeConnections.filter(connection => connection.matches(newConnection)).length, 1, 'Did not find newConnection in active connections');
|
||||
});
|
||||
});
|
||||
@@ -12,12 +12,12 @@ import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { TestCredentialsService } from 'sql/platform/credentials/test/common/testCredentialsService';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { deepClone, deepFreeze } from 'vs/base/common/objects';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import { TestStorageService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { InMemoryStorageService } from 'vs/platform/storage/common/storage';
|
||||
|
||||
suite('ConnectionStore', () => {
|
||||
let defaultNamedProfile: IConnectionProfile = deepFreeze({
|
||||
@@ -142,7 +142,7 @@ suite('ConnectionStore', () => {
|
||||
// Given 5 is the max # creds
|
||||
const numCreds = 6;
|
||||
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -169,7 +169,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('getRecentlyUsedConnections should return connection for given provider', () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
const connectionStore = new ConnectionStore(storageService, configurationService,
|
||||
@@ -181,7 +181,7 @@ suite('ConnectionStore', () => {
|
||||
|
||||
test('addActiveConnection should add same connection exactly once', async () => {
|
||||
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -204,7 +204,7 @@ suite('ConnectionStore', () => {
|
||||
|
||||
// Setup credential store to capture credentials sent to it
|
||||
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -251,7 +251,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('can clear connections list', async () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -268,7 +268,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('isPasswordRequired should return true for MSSQL SqlLogin', () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -279,7 +279,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('isPasswordRequired should return true for MSSQL SqlLogin for connection profile object', () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -291,7 +291,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('isPasswordRequired should return false if the password is not required in capabilities', () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -318,7 +318,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('saveProfile should save the password after the profile is saved', async () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -335,7 +335,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('getGroupFromId returns undefined when there is no group with the given ID', () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -346,7 +346,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('getGroupFromId returns the group that has the given ID', () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -384,7 +384,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('getProfileWithoutPassword can return the profile without credentials in the password property or options dictionary', () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -402,7 +402,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('addPassword gets the password from the credentials service', async () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -422,7 +422,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('getConnectionProfileGroups', async () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -459,7 +459,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('removing connection correctly removes', async () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
@@ -484,7 +484,7 @@ suite('ConnectionStore', () => {
|
||||
});
|
||||
|
||||
test('getRecentlyUsedConnections correctly fills in group names', async () => {
|
||||
const storageService = new TestStorageService();
|
||||
const storageService = new InMemoryStorageService();
|
||||
const configurationService = new TestConfigurationService();
|
||||
const credentialsService = new TestCredentialsService();
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ConnectionProfile } from 'sql/platform/connection/common/connectionProf
|
||||
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
|
||||
import * as azdata from 'azdata';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
|
||||
// Test stubs for commonly used objects
|
||||
|
||||
|
||||
Reference in New Issue
Block a user