Skip to content

[JUJU-2271] PatchEnvironment now correctly unsets env vars#169

Merged
jack-w-shaw merged 2 commits intojuju:masterfrom
jack-w-shaw:JUJU-2271_fix_bug_unsetting_envvars
Nov 28, 2022
Merged

[JUJU-2271] PatchEnvironment now correctly unsets env vars#169
jack-w-shaw merged 2 commits intojuju:masterfrom
jack-w-shaw:JUJU-2271_fix_bug_unsetting_envvars

Conversation

@jack-w-shaw
Copy link
Copy Markdown
Member

@jack-w-shaw jack-w-shaw commented Nov 28, 2022

os.GetEnv doesn't distinguish between unset vars and vars set to the empty string. However, LookupEnv does. This means PatchEnvironment would leave behind env vars set to the empty string when they were previously unset

These env var would then be picked up by LookupEnv, which can cause unexpected errors.

Update dependencies as a drive-by

QA Steps

  • Verify unit tests pass

  • Verify juju unit testing suite passes as usual using this in place of juju/testing

  • Also, write a test for some code which uses os.LookupEnv, branching based it's second return var, and performs some validation on the env var value. Perhaps you are wish to parse a boolean config option from your environment.
    Verify these tests fail when you PatchEnvironment with upstream. Then verify the pass with this iteration

@jack-w-shaw jack-w-shaw force-pushed the JUJU-2271_fix_bug_unsetting_envvars branch from 9050411 to 5278ee0 Compare November 28, 2022 14:00
Copy link
Copy Markdown
Member

@manadart manadart left a comment

Choose a reason for hiding this comment

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

Might as well do a go mod tidy to pick up all the latest versions of the dependencies.

Comment thread patch_test.go Outdated
@jack-w-shaw jack-w-shaw force-pushed the JUJU-2271_fix_bug_unsetting_envvars branch from 5278ee0 to 1e9c1e3 Compare November 28, 2022 15:00
os.GetEnv doesn't distinguish between unset vars and vars set to the
empty string. However, LookupEnv does. This means PatchEnvironment would
leave behind env vars set to the empty string when they were previously
unset

These env var would then be picked up by LookupEnv, which can cause
unexpected errors.
@jack-w-shaw jack-w-shaw force-pushed the JUJU-2271_fix_bug_unsetting_envvars branch from 1e9c1e3 to 80ad743 Compare November 28, 2022 15:02
@jack-w-shaw jack-w-shaw merged commit 0e4da91 into juju:master Nov 28, 2022
@jack-w-shaw jack-w-shaw deleted the JUJU-2271_fix_bug_unsetting_envvars branch November 28, 2022 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants