Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add env attribute to go_test rule #1973

Closed
wants to merge 1 commit into from
Closed

Conversation

blico
Copy link
Contributor

@blico blico commented Mar 1, 2019

This change adds the env attribute to the go_test rule.

env is a map of environment variables that will be set before the test is run.

@jayconrod
Copy link
Contributor

Why set environment variables in Bazel rules and not in the tests themselves?

If there's a reason environment variables must be set in rules, does it make sense for it to be a common attribute for all test rules in Bazel itself?

rules_go seems like the wrong place for this.

@Globegitter
Copy link
Contributor

Globegitter commented Mar 1, 2019

We have also run into cases where it is useful to set env vars before a target runs (not so much in go but especially js). I opened bazelbuild/bazel#7364 for that, @blico might be useful to +1 that issue as well :)

@Globegitter
Copy link
Contributor

Globegitter commented Mar 1, 2019

Btw currently as a workaround for our cases we are using the command rule from here: https://github.com/atlassian/bazel-tools/blob/master/multirun/README.md

@jayconrod
Copy link
Contributor

This PR won't actually set environment variables before the target runs. Instead, they'll be set in main. init functions would not see the new environment variables. So I'd encourage people to write their own TestMain functions to set variable instead so it's clear what's happening. This would let the same tests work with go test, too.

bazelbuild/bazel#7364 would be able to set variables before the test executes. I think that's a better solution.

@blico
Copy link
Contributor Author

blico commented Mar 1, 2019

Thank you for the feedback.

I will close this PR and look into bazelbuild/bazel#7364

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

Successfully merging this pull request may close these issues.

4 participants