Skip to content

Commit

Permalink
Merge pull request #110 from cloudfoundry/remove-use-isolated-env
Browse files Browse the repository at this point in the history
Remove `UseIsolatedEnv` from `system.Command`
  • Loading branch information
ystros authored Feb 7, 2025
2 parents 82e8451 + 4adbdc9 commit 497d9f4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
7 changes: 3 additions & 4 deletions system/cmd_runner_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
)

type Command struct {
Name string
Args []string
Env map[string]string
UseIsolatedEnv bool
Name string
Args []string
Env map[string]string

WorkingDir string

Expand Down
11 changes: 1 addition & 10 deletions system/exec_cmd_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package system
import (
"os"
"os/exec"
"runtime"
"strings"

boshlog "github.com/cloudfoundry/bosh-utils/logger"
Expand Down Expand Up @@ -80,15 +79,7 @@ func (r execCmdRunner) buildComplexCommand(cmd Command) *exec.Cmd {

execCmd.Dir = cmd.WorkingDir

var env []string
if !cmd.UseIsolatedEnv {
env = os.Environ()
}
if cmd.UseIsolatedEnv && runtime.GOOS == "windows" {
panic("UseIsolatedEnv is not supported on Windows")
}

execCmd.Env = mergeEnv(env, cmd.Env)
execCmd.Env = mergeEnv(os.Environ(), cmd.Env)

return execCmd
}
Expand Down
19 changes: 0 additions & 19 deletions system/exec_cmd_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ var _ = Describe("execCmdRunner", func() {

It("run complex command with env", func() {
cmd := osSpecificCommand("env")
cmd.UseIsolatedEnv = false
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -141,23 +140,6 @@ var _ = Describe("execCmdRunner", func() {
Expect(status).To(Equal(0))
})

It("runs complex command with specific env", func() {
cmd := osSpecificCommand("env")
cmd.UseIsolatedEnv = true
if runtime.GOOS == "windows" {
Expect(func() { runner.RunComplexCommand(cmd) }).To(Panic()) //nolint:errcheck
} else {
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())

envVars := parseEnvFields(stdout, true)
Expect(envVars).To(HaveKeyWithValue("FOO", "BAR"))
Expect(envVars).ToNot(HaveKey("PATH"))
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
}
})

It("uses the env vars specified in the Command", func() {
GinkgoT().Setenv("_FOO", "BAR")

Expand Down Expand Up @@ -351,7 +333,6 @@ var _ = Describe("execCmdRunner", func() {

It("allows setting custom env variable in addition to inheriting process env variables", func() {
cmd := osSpecificCommand("env")
cmd.UseIsolatedEnv = false

process, err := runner.RunComplexCommandAsync(cmd)
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 497d9f4

Please sign in to comment.