add Setenv function #273

Merged
merged 1 commit into from Apr 20, 2017

Conversation

Projects
None yet
6 participants
Owner

rogpeppe commented Apr 20, 2017

This makes it easier to override environment variables
since just appending environment variables doesn't
work any more (and never did for non-Go programs).
See golang/go#19877 for
background.

LGTM

+ {"foo=1", []string{"foo=1", "arble="}},
+ {"foo=", []string{"foo=", "arble="}},
+ {"arble=23", []string{"foo=bar", "arble=23"}},
+ {"zaphod=42", []string{"foo=bar", "arble=", "zaphod=42"}},
@mattyw

mattyw Apr 20, 2017

Member

test for wrong input format

add Setenv function
This makes it easier to override environment variables
since just appending environment variables doesn't
work any more (and never did for non-Go programs).
See golang/go#19877 for
background.
Owner

rogpeppe commented Apr 20, 2017

$$merge$$

seeing Setenv("foo=") makes me wonder if we would want Delenv.

+func Setenv(env []string, entry string) []string {
+ i := strings.Index(entry, "=")
+ if i == -1 {
+ panic("no = in environment entry")
@jameinel

jameinel Apr 20, 2017

Owner

Anything that would be actively used in production, should really not have a panic() in it, since that tends to have the property of crashing all of Juju instead of just having one worker get restarted.

+ if i == -1 {
+ panic("no = in environment entry")
+ }
+ prefix := entry[0 : i+1]
@jameinel

jameinel Apr 20, 2017

Owner

formatting looks odd. Is that really how 'go fmt' formats it?

@rogpeppe

rogpeppe Apr 20, 2017

Owner

yeah, it is.

+
+var _ = gc.Suite(&SetenvSuite{})
+
+var setenvTests = []struct {
@jameinel

jameinel Apr 20, 2017

Owner

It seems odd to have these as a slice outside of the function given that they depend so concretely on the initial setup.

Contributor

jujubot commented Apr 20, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju-utils

@jujubot jujubot merged commit 548369f into juju:master Apr 20, 2017

jujubot added a commit that referenced this pull request Apr 20, 2017

Merge pull request #274 from rogpeppe/032-setenv-tweaks
make Setenv ignore malformed entries rather than panic

Responding to JAM's review on PR #273.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment