-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/goDebugConfiguration: combine envFile and env
With the resolveDebugConfigurationWithSubstitutedVariables, we can read envFile and combine it into the env property from the extension host. Delve DAP will handle only the env arg and not have any special handling for envFile. So, processing it from the extension side makes more sense for long term. This move allows us to centralize the .env file read support. For backwards compatibility, I left the logic in the old DA but removed it from the new delve DAP DA. Fixes #452 Updates #23 Change-Id: I641eb2e62051985ba3486901483ad796256aba2c Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/248659 Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Polina Sokolova <polina@google.com>
- Loading branch information
Showing
5 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import assert = require('assert'); | ||
import fs = require('fs'); | ||
import os = require('os'); | ||
import path = require('path'); | ||
import sinon = require('sinon'); | ||
import vscode = require('vscode'); | ||
import { GoDebugConfigurationProvider } from '../../src/goDebugConfiguration'; | ||
import goEnv = require('../../src/goEnv'); | ||
import { updateGoVarsFromConfig } from '../../src/goInstallTools'; | ||
import { getCurrentGoPath, rmdirRecursive } from '../../src/util'; | ||
|
||
suite('Debug Environment Variable Merge Test', () => { | ||
const debugConfigProvider = new GoDebugConfigurationProvider(); | ||
|
||
suiteSetup(async () => { | ||
await updateGoVarsFromConfig(); | ||
|
||
// Set up the test fixtures. | ||
const fixtureSourcePath = path.join(__dirname, '..', '..', '..', 'test', 'fixtures'); | ||
const filePath = path.join(fixtureSourcePath, 'baseTest', 'test.go'); | ||
await vscode.workspace.openTextDocument(vscode.Uri.file(filePath)); | ||
}); | ||
|
||
suiteTeardown(() => { | ||
vscode.commands.executeCommand('workbench.action.closeActiveEditor'); | ||
}); | ||
|
||
let sandbox: sinon.SinonSandbox; | ||
let tmpDir = ''; | ||
const toolExecutionEnv: NodeJS.Dict<string> = {}; | ||
setup(() => { | ||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'godebugconfig_test')); | ||
sandbox = sinon.createSandbox(); | ||
|
||
}); | ||
|
||
teardown(() => { | ||
sandbox.restore(); | ||
rmdirRecursive(tmpDir); | ||
}); | ||
|
||
interface Input { | ||
env?: { [key: string]: any }; | ||
envFile?: string|string[]; | ||
toolsEnv?: { [key: string]: any}; | ||
} | ||
|
||
function runTest(input: Input, expected: { [key: string]: any}) { | ||
sandbox.stub(goEnv, 'toolExecutionEnvironment').returns(input.toolsEnv || {}); | ||
const config = debugConfigProvider.resolveDebugConfigurationWithSubstitutedVariables(undefined, { | ||
type: 'go', | ||
name: 'Launch', | ||
request: 'launch', | ||
env: input.env, | ||
envFile: input.envFile, | ||
}); | ||
|
||
const actual = config.env; | ||
assert.deepStrictEqual(actual, expected); | ||
} | ||
|
||
test('works with empty launchArgs', () => { | ||
runTest({}, {}); | ||
}); | ||
|
||
test('toolsEnvVars is propagated', () => { | ||
const toolsEnv = { | ||
GOPATH: '/gopath', | ||
GOOS: 'valueFromToolsEnv'}; | ||
|
||
runTest({toolsEnv}, { | ||
GOPATH: '/gopath', | ||
GOOS: 'valueFromToolsEnv'}); | ||
}); | ||
|
||
test('preserves settings from launchArgs.env', () => { | ||
const env = {GOPATH: 'valueFromEnv', GOOS: 'valueFromEnv2'}; | ||
runTest({env}, { | ||
GOPATH: 'valueFromEnv', | ||
GOOS: 'valueFromEnv2'}); | ||
}); | ||
|
||
test('preserves settings from launchArgs.envFile', () => { | ||
const envFile = path.join(tmpDir, 'env'); | ||
fs.writeFileSync(envFile, 'GOPATH=valueFromEnvFile'); | ||
runTest({envFile}, {GOPATH: 'valueFromEnvFile'}); | ||
}); | ||
|
||
test('launchArgs.env overwrites launchArgs.envFile', () => { | ||
const env = {SOMEVAR1: 'valueFromEnv'}; | ||
const envFile = path.join(tmpDir, 'env'); | ||
fs.writeFileSync(envFile, [ | ||
'SOMEVAR1=valueFromEnvFile1', | ||
'SOMEVAR2=valueFromEnvFile2'].join('\n')); | ||
|
||
runTest({ env, envFile }, { | ||
SOMEVAR1: 'valueFromEnv', | ||
SOMEVAR2: 'valueFromEnvFile2'}); | ||
}); | ||
}); |