Fix test being potentially muddied by local ENV #21586
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
bundle exec rspec
from the root directory to see all new and existing tests passbundle exec rubocop -a
to ensure the code style is validci/circleci
builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)Motivation and Context
When running
bundle exec rspec
, if you have an environment variable likeSENTRY_AUTH_TOKEN
defined in your local environment (e.g. via your~/.zshrc
), its value will be picked up when runningrspec
, and that will make the expectations of theupload_symbols_to_sentry
spec fail.This is because the spec is testing cases where the user did not provide a token (and expect the action to raise an error in such cases), but when you have the ENV var defined on your Mac, it makes the action being run by the test picking it up as the token so the action doesn't fail and the test doesn't test what's expected of it.
Description
Stub
ENV#[]
to returnnil
for all those tests so that it does not risk being polluted by the local environment whenbundle exec rspec
is being run.PS: Note that I suspect many other specs are subject to a similar issue of accidentally picking up the local environment. This is just the only one that kept causing me trouble because I happen to have
SENTRY_AUTH_TOKEN
defined in my~/.zshrc
, but I'm sure if I had other env vars associated with some actions'ConfigItem(env: …)
defined in my local env that would make other tests fail for the same reason. That being said, I don't have the bandwidth to investigate all the potential cases where this could happen, so I figured I'd just fix the one that caused me trouble (and let others apply a similar patch in the other specs if they encounter a similar issue on their end on other test cases)Testing Steps
Run the following:
If you run these lines on
master
(before this PR) you should end up with the following test failure:If you run those same lines on this PR's branch, those tests should now pass.