mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-25 14:20:30 -04:00
Merge from vscode 31e03b8ffbb218a87e3941f2b63a249f061fe0e4 (#4986)
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { equal } from 'assert';
|
||||
import { equal, fail } from 'assert';
|
||||
import * as os from 'os';
|
||||
|
||||
import { resolveQueryFilePath } from 'sql/workbench/services/insights/common/insightsUtils';
|
||||
import { TestWindowService } from 'sqltest/stubs/windowTestService';
|
||||
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
@@ -16,69 +15,129 @@ import { getRandomTestPath } from 'vs/base/test/node/testUtils';
|
||||
import { Workspace, toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
|
||||
import { ConfigurationResolverService } from 'vs/workbench/services/configurationResolver/browser/configurationResolverService';
|
||||
import { TestContextService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { IExtensionHostDebugParams, IDebugParams, ParsedArgs } from 'vs/platform/environment/common/environment';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
|
||||
|
||||
class TestEnvironmentService implements IWorkbenchEnvironmentService {
|
||||
machineSettingsHome: string;
|
||||
machineSettingsPath: string;
|
||||
extensionDevelopmentLocationURI?: URI[];
|
||||
|
||||
constructor(private userEnv: { [key: string]: any }) {
|
||||
|
||||
}
|
||||
|
||||
get configuration(): IWindowConfiguration {
|
||||
return {
|
||||
userEnv: this.userEnv
|
||||
} as IWindowConfiguration;
|
||||
}
|
||||
|
||||
_serviceBrand: any;
|
||||
args: ParsedArgs;
|
||||
execPath: string;
|
||||
cliPath: string;
|
||||
appRoot: string;
|
||||
userHome: string;
|
||||
userDataPath: string;
|
||||
appNameLong: string;
|
||||
appQuality?: string;
|
||||
appSettingsHome: string;
|
||||
appSettingsPath: string;
|
||||
appKeybindingsPath: string;
|
||||
settingsSearchBuildId?: number;
|
||||
settingsSearchUrl?: string;
|
||||
globalStorageHome: string;
|
||||
workspaceStorageHome: string;
|
||||
backupHome: string;
|
||||
backupWorkspacesPath: string;
|
||||
untitledWorkspacesHome: URI;
|
||||
isExtensionDevelopment: boolean;
|
||||
disableExtensions: boolean | string[];
|
||||
builtinExtensionsPath: string;
|
||||
extensionsPath: string;
|
||||
extensionTestsLocationURI?: URI;
|
||||
debugExtensionHost: IExtensionHostDebugParams;
|
||||
debugSearch: IDebugParams;
|
||||
logExtensionHostCommunication: boolean;
|
||||
isBuilt: boolean;
|
||||
wait: boolean;
|
||||
status: boolean;
|
||||
log?: string;
|
||||
logsPath: string;
|
||||
verbose: boolean;
|
||||
skipGettingStarted: boolean;
|
||||
skipReleaseNotes: boolean;
|
||||
skipAddToRecentlyOpened: boolean;
|
||||
mainIPCHandle: string;
|
||||
sharedIPCHandle: string;
|
||||
nodeCachedDataDir?: string;
|
||||
installSourcePath: string;
|
||||
disableUpdates: boolean;
|
||||
disableCrashReporter: boolean;
|
||||
driverHandle?: string;
|
||||
driverVerbose: boolean;
|
||||
}
|
||||
|
||||
suite('Insights Utils tests', function () {
|
||||
let testRootPath: string;
|
||||
let queryFileDir: string;
|
||||
let queryFilePath: string;
|
||||
|
||||
suiteSetup(done => {
|
||||
suiteSetup(async () => {
|
||||
// Create test file - just needs to exist for verifying the path resolution worked correctly
|
||||
testRootPath = path.join(os.tmpdir(), 'adstests');
|
||||
queryFileDir = getRandomTestPath(testRootPath, 'insightsutils');
|
||||
pfs.mkdirp(queryFileDir).then(() => {
|
||||
queryFilePath = path.join(queryFileDir, 'test.sql');
|
||||
pfs.writeFile(queryFilePath, '').then(done());
|
||||
});
|
||||
|
||||
await pfs.mkdirp(queryFileDir);
|
||||
queryFilePath = path.join(queryFileDir, 'test.sql');
|
||||
await pfs.writeFile(queryFilePath, '');
|
||||
});
|
||||
|
||||
test('resolveQueryFilePath resolves path correctly with fully qualified path', async () => {
|
||||
let configurationResolverService = new ConfigurationResolverService(
|
||||
new TestWindowService({}),
|
||||
undefined,
|
||||
const configurationResolverService = new ConfigurationResolverService(
|
||||
undefined,
|
||||
new TestEnvironmentService({}),
|
||||
undefined,
|
||||
undefined,
|
||||
new TestContextService(),
|
||||
undefined);
|
||||
|
||||
let resolvedPath = await resolveQueryFilePath(queryFilePath, new TestContextService(), configurationResolverService);
|
||||
const resolvedPath = await resolveQueryFilePath(queryFilePath, new TestContextService(), configurationResolverService);
|
||||
equal(resolvedPath, queryFilePath);
|
||||
});
|
||||
|
||||
test('resolveQueryFilePath resolves path correctly with workspaceRoot var and non-empty workspace containing file', async () => {
|
||||
// Create mock context service with our test folder added as a workspace folder for resolution
|
||||
let contextService = new TestContextService(
|
||||
const contextService = new TestContextService(
|
||||
new Workspace(
|
||||
'TestWorkspace',
|
||||
toWorkspaceFolders([{ path: queryFileDir }])
|
||||
));
|
||||
let configurationResolverService = new ConfigurationResolverService(
|
||||
new TestWindowService({}),
|
||||
undefined,
|
||||
const configurationResolverService = new ConfigurationResolverService(
|
||||
undefined,
|
||||
new TestEnvironmentService({}),
|
||||
undefined,
|
||||
undefined,
|
||||
contextService,
|
||||
undefined);
|
||||
|
||||
let resolvedPath = await resolveQueryFilePath(path.join('${workspaceRoot}', 'test.sql'), contextService, configurationResolverService);
|
||||
const resolvedPath = await resolveQueryFilePath(path.join('${workspaceRoot}', 'test.sql'), contextService, configurationResolverService);
|
||||
equal(resolvedPath, queryFilePath);
|
||||
});
|
||||
|
||||
test('resolveQueryFilePath throws with workspaceRoot var and non-empty workspace not containing file', async (done) => {
|
||||
let tokenizedPath = path.join('${workspaceRoot}', 'test.sql');
|
||||
const tokenizedPath = path.join('${workspaceRoot}', 'test.sql');
|
||||
// Create mock context service with a folder NOT containing our test file to verify it returns original path
|
||||
let contextService = new TestContextService(
|
||||
const contextService = new TestContextService(
|
||||
new Workspace(
|
||||
'TestWorkspace',
|
||||
toWorkspaceFolders([{ path: os.tmpdir() }])
|
||||
));
|
||||
let configurationResolverService = new ConfigurationResolverService(
|
||||
new TestWindowService({}),
|
||||
undefined,
|
||||
const configurationResolverService = new ConfigurationResolverService(
|
||||
undefined,
|
||||
new TestEnvironmentService({}),
|
||||
undefined,
|
||||
undefined,
|
||||
contextService,
|
||||
@@ -86,6 +145,7 @@ suite('Insights Utils tests', function () {
|
||||
|
||||
try {
|
||||
await resolveQueryFilePath(tokenizedPath, contextService, configurationResolverService);
|
||||
fail('Should have thrown');
|
||||
}
|
||||
catch (e) {
|
||||
done();
|
||||
@@ -93,15 +153,14 @@ suite('Insights Utils tests', function () {
|
||||
});
|
||||
|
||||
test('resolveQueryFilePath throws with workspaceRoot var and empty workspace', async (done) => {
|
||||
let tokenizedPath = path.join('${workspaceRoot}', 'test.sql');
|
||||
const tokenizedPath = path.join('${workspaceRoot}', 'test.sql');
|
||||
// Create mock context service with an empty workspace
|
||||
let contextService = new TestContextService(
|
||||
const contextService = new TestContextService(
|
||||
new Workspace(
|
||||
'TestWorkspace'));
|
||||
let configurationResolverService = new ConfigurationResolverService(
|
||||
new TestWindowService({}),
|
||||
undefined,
|
||||
const configurationResolverService = new ConfigurationResolverService(
|
||||
undefined,
|
||||
new TestEnvironmentService({}),
|
||||
undefined,
|
||||
undefined,
|
||||
contextService,
|
||||
@@ -109,6 +168,7 @@ suite('Insights Utils tests', function () {
|
||||
|
||||
try {
|
||||
await resolveQueryFilePath(tokenizedPath, contextService, configurationResolverService);
|
||||
fail('Should have thrown');
|
||||
}
|
||||
catch (e) {
|
||||
done();
|
||||
@@ -116,47 +176,44 @@ suite('Insights Utils tests', function () {
|
||||
});
|
||||
|
||||
test('resolveQueryFilePath resolves path correctly with env var and empty workspace', async () => {
|
||||
let contextService = new TestContextService(
|
||||
const contextService = new TestContextService(
|
||||
new Workspace('TestWorkspace'));
|
||||
|
||||
// Create mock window service with env variable containing test folder for resolution
|
||||
let configurationResolverService = new ConfigurationResolverService(
|
||||
new TestWindowService({ TEST_PATH: queryFileDir }),
|
||||
undefined,
|
||||
const configurationResolverService = new ConfigurationResolverService(
|
||||
undefined,
|
||||
new TestEnvironmentService({ TEST_PATH: queryFileDir }),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined);
|
||||
|
||||
let resolvedPath = await resolveQueryFilePath(path.join('${env:TEST_PATH}', 'test.sql'), contextService, configurationResolverService);
|
||||
const resolvedPath = await resolveQueryFilePath(path.join('${env:TEST_PATH}', 'test.sql'), contextService, configurationResolverService);
|
||||
equal(resolvedPath, queryFilePath);
|
||||
});
|
||||
|
||||
test('resolveQueryFilePath resolves path correctly with env var and non-empty workspace', async () => {
|
||||
let contextService = new TestContextService(
|
||||
const contextService = new TestContextService(
|
||||
new Workspace('TestWorkspace', toWorkspaceFolders([{ path: os.tmpdir() }])));
|
||||
|
||||
// Create mock window service with env variable containing test folder for resolution
|
||||
let configurationResolverService = new ConfigurationResolverService(
|
||||
new TestWindowService({ TEST_PATH: queryFileDir }),
|
||||
undefined,
|
||||
const configurationResolverService = new ConfigurationResolverService(
|
||||
undefined,
|
||||
new TestEnvironmentService({ TEST_PATH: queryFileDir }),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined);
|
||||
|
||||
let resolvedPath = await resolveQueryFilePath(path.join('${env:TEST_PATH}', 'test.sql'), contextService, configurationResolverService);
|
||||
const resolvedPath = await resolveQueryFilePath(path.join('${env:TEST_PATH}', 'test.sql'), contextService, configurationResolverService);
|
||||
equal(resolvedPath, queryFilePath);
|
||||
});
|
||||
|
||||
test('resolveQueryFilePath throws if invalid param var specified', async (done) => {
|
||||
let invalidPath = path.join('${INVALID}', 'test.sql');
|
||||
let configurationResolverService = new ConfigurationResolverService(
|
||||
new TestWindowService({}),
|
||||
undefined,
|
||||
const invalidPath = path.join('${INVALID}', 'test.sql');
|
||||
const configurationResolverService = new ConfigurationResolverService(
|
||||
undefined,
|
||||
new TestEnvironmentService({}),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -164,8 +221,8 @@ suite('Insights Utils tests', function () {
|
||||
|
||||
try {
|
||||
await resolveQueryFilePath(invalidPath, new TestContextService(), configurationResolverService);
|
||||
}
|
||||
catch (e) {
|
||||
fail('Should have thrown');
|
||||
} catch (e) {
|
||||
done();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { IDimension } from 'vs/editor/common/editorCommon';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
export class EditorGroupTestService implements IEditorGroupsService {
|
||||
willRestoreEditors: boolean;
|
||||
dimension: IDimension;
|
||||
whenRestored: Promise<void>;
|
||||
centerLayout(active: boolean): void {
|
||||
|
||||
Reference in New Issue
Block a user