env: Format() emits only managed vars, not entire process env
This commit is contained in:
parent
1dbc75cecc
commit
391f633785
|
|
@ -106,12 +106,14 @@ func All() map[string]string {
|
|||
return m
|
||||
}
|
||||
|
||||
// Format returns the full process environment as NAME=VALUE lines, suitable
|
||||
// for serving as ollie/env.
|
||||
// Format returns the managed environment variables as NAME=VALUE lines,
|
||||
// suitable for serving as ollie/env.
|
||||
func Format() []byte {
|
||||
var sb strings.Builder
|
||||
for _, pair := range os.Environ() {
|
||||
fmt.Fprintf(&sb, "%s\n", pair)
|
||||
for _, k := range managed {
|
||||
if v := os.Getenv(k); v != "" {
|
||||
fmt.Fprintf(&sb, "%s=%s\n", k, v)
|
||||
}
|
||||
}
|
||||
return []byte(sb.String())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ func TestAll(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFormat(t *testing.T) {
|
||||
t.Setenv("OLLIE_TEST_FMT", "xyz")
|
||||
t.Setenv("OLLIE_TMP_PATH", "/tmp/test-fmt")
|
||||
out := string(Format())
|
||||
if !strings.Contains(out, "OLLIE_TEST_FMT=xyz") {
|
||||
if !strings.Contains(out, "OLLIE_TMP_PATH=/tmp/test-fmt") {
|
||||
t.Errorf("Format() missing expected var, got:\n%s", out)
|
||||
}
|
||||
// Every line should be NAME=VALUE\n
|
||||
|
|
|
|||
Reference in New Issue