test/integration: use MockCfg for debug setting test
resolveDebugConfiguration uses 'inspect' API to determine
whether the debug setting is default or user-configured.
So, we need to mock the inspect method too.
Utilize MockCfg used in the config.test.ts and move it to
the mock directory.
Fixes golang/vscode-go#1566
Change-Id: I49f703c69e3f4b4455004a37bb84ee18080fc942
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/327769
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/test/integration/config.test.ts b/test/integration/config.test.ts
index 1d7eee4..525b42d 100644
--- a/test/integration/config.test.ts
+++ b/test/integration/config.test.ts
@@ -9,7 +9,7 @@
import * as assert from 'assert';
import { Configuration } from '../../src/config';
-import vscode = require('vscode');
+import { MockCfg } from '../mocks/MockCfg';
suite('GoConfiguration Tests', () => {
function check(trusted: boolean, workspaceConfig: { [key: string]: any }, key: string, expected: any) {
@@ -68,48 +68,3 @@
checkGopls(false, { env: { GOBIN: 'foo' } }, 'env', { GOBIN: 'foo' });
});
});
-
-// tslint:disable: no-any
-class MockCfg implements vscode.WorkspaceConfiguration {
- private map: Map<string, any>;
- private wrapped: vscode.WorkspaceConfiguration;
-
- constructor(workspaceSettings: { [key: string]: any } = {}) {
- // getter
- Object.defineProperties(this, Object.getOwnPropertyDescriptors(workspaceSettings));
- this.map = new Map<string, any>(Object.entries(workspaceSettings));
- this.wrapped = vscode.workspace.getConfiguration('go'); // intentionally using vscode API directly.
- }
-
- // tslint:disable: no-any
- public get(section: string, defaultValue?: any): any {
- if (this.map.has(section)) {
- return this.map.get(section);
- }
- return this.wrapped.get(section, defaultValue);
- }
-
- public has(section: string): boolean {
- if (this.map.has(section)) {
- return true;
- }
- return this.wrapped.has(section);
- }
-
- public inspect<T>(section: string) {
- const i = this.wrapped.inspect<T>(section);
- if (this.map.has(section)) {
- i.workspaceValue = this.map.get(section);
- }
- return i;
- }
-
- public update(
- section: string,
- value: any,
- configurationTarget?: boolean | vscode.ConfigurationTarget,
- overrideInLanguage?: boolean
- ): Thenable<void> {
- throw new Error('Method not implemented.');
- }
-}
diff --git a/test/integration/goDebugConfiguration.test.ts b/test/integration/goDebugConfiguration.test.ts
index 8199bbd..508c0d4 100644
--- a/test/integration/goDebugConfiguration.test.ts
+++ b/test/integration/goDebugConfiguration.test.ts
@@ -13,6 +13,7 @@
import { rmdirRecursive } from '../../src/util';
import goEnv = require('../../src/goEnv');
import { isInPreviewMode } from '../../src/goLanguageServer';
+import { MockCfg } from '../mocks/MockCfg';
suite('Debug Environment Variable Merge Test', () => {
const debugConfigProvider = new GoDebugConfigurationProvider();
@@ -211,23 +212,21 @@
// When this expected behavior changes, this test can be updated.
// Run resolveDebugConfiguration with the default workspace settings.
- const goConfig = Object.create(getGoConfig(), {
+ const goConfig = new MockCfg({
delveConfig: {
- value: {
- dlvLoadConfig: {
- followPointers: false,
- maxVariableRecurse: 3,
- maxStringLen: 32,
- maxArrayValues: 32,
- maxStructFields: 5
- },
- apiVersion: 1,
- showGlobalVariables: true,
- debugAdapter: 'dlv-dap',
- substitutePath: [{ from: 'hello', to: 'goodbye' }]
- }
+ dlvLoadConfig: {
+ followPointers: false,
+ maxVariableRecurse: 3,
+ maxStringLen: 32,
+ maxArrayValues: 32,
+ maxStructFields: 5
+ },
+ apiVersion: 1,
+ showGlobalVariables: true,
+ debugAdapter: 'dlv-dap',
+ substitutePath: [{ from: 'hello', to: 'goodbye' }]
}
- }) as vscode.WorkspaceConfiguration;
+ });
sinon.stub(config, 'getGoConfig').returns(goConfig);
const cfg = {
@@ -259,23 +258,21 @@
// When this expected behavior changes, this test can be updated.
// Run resolveDebugConfiguration with the default workspace settings.
- const goConfig = Object.create(getGoConfig(), {
+ const goConfig = new MockCfg({
delveConfig: {
- value: {
- dlvLoadConfig: {
- followPointers: false,
- maxVariableRecurse: 3,
- maxStringLen: 32,
- maxArrayValues: 32,
- maxStructFields: 5
- },
- apiVersion: 1,
- showGlobalVariables: true,
- debugAdapter: 'dlv-dap',
- substitutePath: [{ from: 'hello', to: 'goodbye' }]
- }
+ dlvLoadConfig: {
+ followPointers: false,
+ maxVariableRecurse: 3,
+ maxStringLen: 32,
+ maxArrayValues: 32,
+ maxStructFields: 5
+ },
+ apiVersion: 1,
+ showGlobalVariables: true,
+ debugAdapter: 'dlv-dap',
+ substitutePath: [{ from: 'hello', to: 'goodbye' }]
}
- }) as vscode.WorkspaceConfiguration;
+ });
sinon.stub(config, 'getGoConfig').returns(goConfig);
const cfg: vscode.DebugConfiguration = {
diff --git a/test/mocks/MockCfg.ts b/test/mocks/MockCfg.ts
new file mode 100644
index 0000000..99a8735
--- /dev/null
+++ b/test/mocks/MockCfg.ts
@@ -0,0 +1,63 @@
+/* eslint-disable @typescript-eslint/no-unused-vars */
+/* eslint-disable @typescript-eslint/no-explicit-any */
+/*---------------------------------------------------------
+ * Copyright 2021 The Go Authors. All rights reserved.
+ * Licensed under the MIT License. See LICENSE in the project root for license information.
+ *--------------------------------------------------------*/
+'use strict';
+import vscode = require('vscode');
+
+// tslint:disable: no-any
+export class MockCfg implements vscode.WorkspaceConfiguration {
+ private map: Map<string, any>;
+ private wrapped: vscode.WorkspaceConfiguration;
+
+ constructor(workspaceSettings: { [key: string]: any } = {}) {
+ // getter
+ Object.defineProperties(this, Object.getOwnPropertyDescriptors(workspaceSettings));
+ this.map = new Map<string, any>(Object.entries(workspaceSettings));
+ this.wrapped = vscode.workspace.getConfiguration('go'); // intentionally using vscode API directly.
+ }
+
+ // tslint:disable: no-any
+ public get(section: string, defaultValue?: any): any {
+ if (this.map.has(section)) {
+ return this.map.get(section);
+ }
+ return this.wrapped.get(section, defaultValue);
+ }
+
+ public has(section: string): boolean {
+ if (this.map.has(section)) {
+ return true;
+ }
+ return this.wrapped.has(section);
+ }
+
+ public inspect<T>(section: string) {
+ const i = this.wrapped.inspect<T>(section);
+ const part = section.split('.');
+ if (this.map.has(part[0])) {
+ let v: any = this.map.get(part[0]);
+ for (let i = 1; i < part.length; i++) {
+ if (Object.prototype.hasOwnProperty.call(v, part[i])) {
+ v = v[part[i]];
+ } else {
+ v = undefined;
+ break;
+ }
+ }
+ i.workspaceValue = v;
+ }
+ return i;
+ }
+
+ public update(
+ section: string,
+ value: any,
+ configurationTarget?: boolean | vscode.ConfigurationTarget,
+ overrideInLanguage?: boolean
+ ): Thenable<void> {
+ throw new Error('Method not implemented.');
+ }
+}