test/goDebugConfiguration.test.ts: test settings.json debug config effects

The delveConfig user settings applied in settings.json, should be applied
to the debug configuration. Test that these are correctly applied.

Additionally, testFlags and buildFlags do not currently affect the debug
configuration, so we also test that to document that behavior. This behavior
is likely to change and the test should be updated when it does.

This change also reintroduces the --user-data-dir= argument to the launch
configuration for running the integration tests. This starts the test with
the default user settings, so running the tests should not be affected by
the user settings.

Update golang/vscode-go#43

Change-Id: I99c9d7f17892e6766fae731c9288880b109ba3fd
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/267217
Trust: Suzy Mueller <suzmue@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/.gitignore b/.gitignore
index d71de02..e512f32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 node_modules/
 .vscode-test/
 .DS_Store
+.user-data-dir-test/
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 3ec6c82..475ef8c 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -61,6 +61,7 @@
 				"--disable-extensions",
 				"--extensionDevelopmentPath=${workspaceFolder}",
 				"--extensionTestsPath=${workspaceFolder}/out/test/integration/index",
+				"--user-data-dir=${workspaceFolder}/.user-data-dir-test",
 				"--timeout",
 				"999999"
 			],
@@ -86,6 +87,7 @@
 				"--disable-extensions",
 				"--extensionDevelopmentPath=${workspaceFolder}",
 				"--extensionTestsPath=${workspaceFolder}/out/test/gopls/index",
+				"--user-data-dir=${workspaceFolder}/.user-data-dir-test",
 				"--timeout", "999999",
 			],
 			"env": {
diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts
index 1e3d4e4..3d6f4bc 100644
--- a/src/goDebugConfiguration.ts
+++ b/src/goDebugConfiguration.ts
@@ -62,7 +62,7 @@
 		debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;
 
 		const goConfig = getGoConfig(folder && folder.uri);
-		const dlvConfig = goConfig.get<any>('delveConfig');
+		const dlvConfig = goConfig['delveConfig'];
 		let useApiV1 = false;
 		if (debugConfiguration.hasOwnProperty('useApiV1')) {
 			useApiV1 = debugConfiguration['useApiV1'] === true;
diff --git a/test/integration/goDebugConfiguration.test.ts b/test/integration/goDebugConfiguration.test.ts
index da17c3d..61881cd 100644
--- a/test/integration/goDebugConfiguration.test.ts
+++ b/test/integration/goDebugConfiguration.test.ts
@@ -7,7 +7,7 @@
 import { GoDebugConfigurationProvider } from '../../src/goDebugConfiguration';
 import goEnv = require('../../src/goEnv');
 import { updateGoVarsFromConfig } from '../../src/goInstallTools';
-import { getCurrentGoPath, rmdirRecursive } from '../../src/util';
+import { getGoConfig, rmdirRecursive } from '../../src/util';
 
 suite('Debug Environment Variable Merge Test', () => {
 	const debugConfigProvider = new GoDebugConfigurationProvider();
@@ -134,3 +134,148 @@
 		});
 	});
 });
+
+suite('Debug Configuration Merge User Settings', () => {
+	const debugConfigProvider = new GoDebugConfigurationProvider();
+	const utils = require('../../src/util');
+
+	teardown(() => sinon.restore());
+
+	suite(`merge 'go' config from settings.json`, () => {
+		test('go flags config does not affect debug config', () => {
+			// This tests that the testFlags and GOOS and GOARCH set
+			// in settings.json do not affect the resolved debug configuration.
+			// When this expected behavior changes, this test can be updated.
+
+			// Run resolveDebugConfiguration with the default workspace settings.
+			const cfg1 = {
+				name: 'Launch',
+				type: 'go',
+				request: 'launch',
+				mode: 'auto',
+				program: '${fileDirname}',
+			};
+
+			const emptyResult = debugConfigProvider.resolveDebugConfiguration(undefined, cfg1);
+			const goConfig = Object.create(getGoConfig(), {
+				testFlags: {value: '-tags=myTagTest'},
+				buildFlags: {value: '-tags=myTagBuild'},
+				goroot: {value: '/path/to/goroot'},
+				gopath: {value: '/path/to/gopath'}
+			}) as vscode.WorkspaceConfiguration;
+
+			// Adjust the workspace config.
+			sinon.stub(utils, 'getGoConfig').returns(goConfig);
+
+			const cfg2 = {
+				name: 'Launch',
+				type: 'go',
+				request: 'launch',
+				mode: 'auto',
+				program: '${fileDirname}',
+			};
+
+			const filledResult = debugConfigProvider.resolveDebugConfiguration(undefined, cfg2);
+
+			assert.strictEqual(filledResult.name, emptyResult.name);
+			assert.strictEqual(filledResult.type, emptyResult.type);
+			assert.strictEqual(filledResult.mode, emptyResult.mode);
+			assert.strictEqual(filledResult.request, emptyResult.request);
+			assert.strictEqual(filledResult.program, emptyResult.program);
+			assert.strictEqual(filledResult.dlvToolPath, emptyResult.dlvToolPath);
+			assert.strictEqual(filledResult.apiVersion, emptyResult.apiVersion);
+			assert.strictEqual(filledResult.showGlobalVariables, emptyResult.showGlobalVariables);
+		});
+
+		test('delve config in settings.json is added to debug config', () => {
+			// This tests that the testFlags and GOOS and GOARCH set
+			// in settings.json do not affect the resolved debug configuration.
+			// When this expected behavior changes, this test can be updated.
+
+			// Run resolveDebugConfiguration with the default workspace settings.
+			const goConfig = Object.create(getGoConfig(), {
+				delveConfig: { value: {
+						dlvLoadConfig: {
+							followPointers: false,
+							maxVariableRecurse: 3,
+							maxStringLen: 32,
+							maxArrayValues: 32,
+							maxStructFields: 5
+						},
+						apiVersion: 1,
+						showGlobalVariables: true
+					}
+				}
+			}) as vscode.WorkspaceConfiguration;
+			sinon.stub(utils, 'getGoConfig').returns(goConfig);
+
+			const cfg = {
+				name: 'Launch',
+				type: 'go',
+				request: 'launch',
+				mode: 'auto',
+				program: '${fileDirname}',
+			};
+
+			const result = debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
+			assert.strictEqual(result.apiVersion, 1);
+			assert.strictEqual(result.showGlobalVariables, true);
+			const dlvLoadConfig = result.dlvLoadConfig;
+			assert.strictEqual(dlvLoadConfig.followPointers, false);
+			assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 3);
+			assert.strictEqual(dlvLoadConfig.maxStringLen, 32);
+			assert.strictEqual(dlvLoadConfig.maxArrayValues, 32);
+			assert.strictEqual(dlvLoadConfig.maxStructFields, 5);
+		});
+
+		test('delve config in settings.json is overriden by launch.json', () => {
+			// This tests that the testFlags and GOOS and GOARCH set
+			// in settings.json do not affect the resolved debug configuration.
+			// When this expected behavior changes, this test can be updated.
+
+			// Run resolveDebugConfiguration with the default workspace settings.
+			const goConfig = Object.create(getGoConfig(), {
+				delveConfig: { value: {
+						dlvLoadConfig: {
+							followPointers: false,
+							maxVariableRecurse: 3,
+							maxStringLen: 32,
+							maxArrayValues: 32,
+							maxStructFields: 5
+						},
+						apiVersion: 1,
+						showGlobalVariables: true
+					}
+				}
+			}) as vscode.WorkspaceConfiguration;
+			sinon.stub(utils, 'getGoConfig').returns(goConfig);
+
+			const cfg = {
+				name: 'Launch',
+				type: 'go',
+				request: 'launch',
+				mode: 'auto',
+				program: '${fileDirname}',
+				apiVersion: 2,
+				showGlobalVariables: false,
+				dlvLoadConfig: {
+					followPointers: true,
+					maxVariableRecurse: 6,
+					maxStringLen: 128,
+					maxArrayValues: 128,
+					maxStructFields: -1
+				},
+			};
+
+			const result = debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
+			assert.strictEqual(result.apiVersion, 2);
+			assert.strictEqual(result.showGlobalVariables, false);
+			const dlvLoadConfig = result.dlvLoadConfig;
+			assert.strictEqual(dlvLoadConfig.followPointers, true);
+			assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 6);
+			assert.strictEqual(dlvLoadConfig.maxStringLen, 128);
+			assert.strictEqual(dlvLoadConfig.maxArrayValues, 128);
+			assert.strictEqual(dlvLoadConfig.maxStructFields, -1);
+		});
+	});
+});
diff --git a/test/runTest.ts b/test/runTest.ts
index c047691..0d27244 100644
--- a/test/runTest.ts
+++ b/test/runTest.ts
@@ -20,7 +20,10 @@
 		await runTests({
 			extensionDevelopmentPath,
 			extensionTestsPath,
-			launchArgs: ['--disable-extensions'],  // disable all other extensions
+			launchArgs: [
+				'--disable-extensions',
+				'--user-data-dir=${workspaceFolder}/.user-data-dir-test',
+			],  // disable all other extensions
 		});
 	} catch (err) {
 		console.error('Failed to run integration tests' + err);
@@ -37,6 +40,7 @@
 			extensionTestsPath: path.resolve(__dirname, './gopls/index'),
 			launchArgs: [
 				'--disable-extensions',  // disable all other extensions
+				'--user-data-dir=${workspaceFolder}/.user-data-dir-test',
 			],
 		});
 	} catch (err) {