Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
19 changes: 0 additions & 19 deletions system/exec_cmd_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ var _ = Describe("execCmdRunner", func() {

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

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

It("runs complex command with specific env", func() {
cmd := GetPlatformCommand("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))
}
})

setupWindowsEnvTest := func(cmdVars map[string]string) (map[string]string, error) {
os.Setenv("_FOO", "BAR") //nolint:errcheck
defer os.Unsetenv("_FOO")
Expand Down Expand Up @@ -319,7 +301,6 @@ var _ = Describe("execCmdRunner", func() {

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

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