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

Set environment variables for go test runs#498

Merged
lukehoban merged 9 commits intomicrosoft:masterfrom
ramya-rao-a:test-env-vars
Sep 29, 2016
Merged

Set environment variables for go test runs#498
lukehoban merged 9 commits intomicrosoft:masterfrom
ramya-rao-a:test-env-vars

Conversation

@ramya-rao-a
Copy link
Copy Markdown
Contributor

Fixes #475

Copy link
Copy Markdown
Member

@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.

Comment thread src/goTest.ts
dir: path.dirname(editor.document.fileName),
functions: testFunctions.map(func => { return func.name; })
});
}).then(null, err => {
Copy link
Copy Markdown
Member

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
Copy Markdown
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

Comment thread src/goTest.ts Outdated
* @param config the test execution configuration.
*/
function goTest(config: TestConfig): Thenable<boolean> {
function goTest(config: TestConfig, goConfig?: vscode.WorkspaceConfiguration): Thenable<boolean> {
Copy link
Copy Markdown
Member

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
Copy Markdown
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

Comment thread src/goTest.ts Outdated
let buildFlags: string[] = goConfig['buildFlags'];
let buildTags: string = goConfig['buildTags'];
let args = ['test', '-v', '-timeout', config.timeout, '-tags', buildTags, ...buildFlags];
let testEnvVars = Object.assign({}, goConfig['testEnvVars'], process.env);
Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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