Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Set environment variables for go test runs #498

Merged
merged 9 commits into from
Sep 29, 2016

Conversation

ramya-rao-a
Copy link
Contributor

Fixes #475

Copy link
Contributor

@lukehoban lukehoban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - just a few notes in review comments.

return goTest({
timeout: timeout,
dir: path.dirname(editor.document.fileName),
functions: testFunctions.map(func => { return func.name; })
});
}).then(null, err => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly minor - but this change will mean that any exceptions thrown during execution of goTest are not handled and reported to console.error. A weirdness of .then on promises. Possibly just leave the additional .then call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the console.error(err) to back where it was and returned promise from there

@@ -116,19 +116,23 @@ export function testCurrentFile(timeout: string) {
*
* @param config the test execution configuration.
*/
function goTest(config: TestConfig): Thenable<boolean> {
function goTest(config: TestConfig, goConfig?: vscode.WorkspaceConfiguration): Thenable<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to make this required and fix up callers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None at all. Made the update to pass goConfig from goMain.ts

let args = ['test', '-v', '-timeout', config.timeout, '-tags', buildTags, ...buildFlags];
let testEnvVars = Object.assign({}, goConfig['testEnvVars'], process.env);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the order need to be changed to ensure that the testEnvVars overrride the process environment settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, nice catch. Corrected

@lukehoban lukehoban merged commit a443750 into microsoft:master Sep 29, 2016
@ramya-rao-a ramya-rao-a deleted the test-env-vars branch January 22, 2017 07:58
@rynop
Copy link

rynop commented Jul 9, 2019

For those trying to figure out how to use this, you have to set a value in your vs code settings.json:

Ex:
"go.testEnvFile": "${workspaceFolder}/.env",

@henrahmagix
Copy link

Or

"go.testEnvVars": {
  "APP_DEBUG": "1",
  "MY_ENV": "my-value"
},

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to set env var before run Go test command
5 participants